gpt4 book ai didi

c# - 如何在 listview.subitem 中添加图像

转载 作者:行者123 更新时间:2023-11-30 19:19:48 26 4
gpt4 key购买 nike

我想知道如何在 ListView 子项中添加图像。

我正在使用此代码在子项中显示文本。

 double Text = "2452";
ListViewItem lItem = new ListViewItem();
lItem.SubItems.Add(Text.ToString());

我想做这样的事情

 ListViewItem lItem = new ListViewItem();
lItem.SubItems.Add(Text.ToString() + "C:\\image.png");

提前致谢。

最佳答案

private void ListView1_DrawColumnHeader(object sender, System.Windows.Forms.DrawListViewColumnHeaderEventArgs e) {
e.DrawDefault = true;
}

private void ListView1_DrawSubItem(object sender, System.Windows.Forms.DrawListViewSubItemEventArgs e) {
if (!(e.Item.SubItems(0) == e.SubItem)) {
e.DrawDefault = false;
e.DrawBackground();
e.Graphics.DrawImage(My.Resources.Image1, e.SubItem.Bounds.Location);
e.Graphics.DrawString(e.SubItem.Text, e.SubItem.Font, new SolidBrush(e.SubItem.ForeColor), (e.SubItem.Bounds.Location.X + My.Resources.Image1.Width), e.SubItem.Bounds.Location.Y);
}
else {
e.DrawDefault = true;
}
}

关于c# - 如何在 listview.subitem 中添加图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7997348/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com