c# - 在 ListViewItem C# 中添加多于 2 个图像

标签 c# image winforms listviewitem

我需要为 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/

相关文章:

c# - 如何使用 MVC 4 上传大文件?

c# - C# 中具有可变内容的字符串插值

java - 如何将文件 (image.gif) 从我的 ".jar"复制到文件夹?

c# - 如何在 WinForms 中绘制图像反射?

C# 应用程序未在 UDPClient.Receive 上接收数据包

c# - WPF App 变成 GeneratedApplication

c# - 在最终不需要计算器的情况下将枚举定义为 2 的标志/幂的任何技巧?

image - 如何使用 apache 或 .htaccess 限制对某种内容的访问?

html - 如何垂直对齐 figcaption 到图中的 img

c# - 在 Winforms web 浏览器控件中使用 ActiveXObject