我需要为 ListView 项添加两个以上的图像,并且我知道我只能使用两个列表:StateImageList 以及通过同时设置 ImageIndex 和 StateImageIndex 的 Large 或 SmallImageLists。 是否有可能在同一个 ListView 项(同一列)上添加两个以上的图像。
谢谢!
最佳答案
如果你想通过代码将图像添加到ListView。 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);
}
}
关于c# - 在 ListViewItem C# 中添加多于 2 个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58432203/