【问题标题】:Add more than 2 images in a ListViewItem C#在 ListViewItem C# 中添加超过 2 个图像
【发布时间】:2020-02-14 08:24:03
【问题描述】:
我需要为列表视图项添加两个以上的图像,并且我知道我只能使用两个列表:StateImageList 以及通过设置 ImageIndex 和 StateImageIndex 的 Large 或 SmallImageLists。
是否有可能在同一个列表视图项(同一列)上添加两个以上的图像。
谢谢!
【问题讨论】:
标签:
c#
image
winforms
listviewitem
【解决方案1】:
如果您想通过代码将图像添加到ListView。列表视图项的两个图像,您可以参考代码。
public void Form_Load(object sender, EventArgs e)
{
DirectoryInfo dir = new DirectoryInfo(@"Path OF Image");
foreach (FileInfo file in dir.GetFiles())
{
try
{
this.imageLists.Images.Add(Image.FromFile(file.FullName));
}
catch{
Console.WriteLine("This is not an image file");
}
}
this.listViewImage.View = View.LargeIcon;
this.imageLists.ImageSize = new Size(50, 50);
this.listViewImage.LargeImageList = this.imageLists;
for (int j = 0; j < this.imageLists.Images.Count; j++)
{
ListViewItem item = new ListViewItem();
item.ImageIndex = j;
this.listView1.Items.Add(item);
}
}