【问题标题】:Add more than 2 images in a ListViewItem C#在 ListViewItem C# 中添加超过 2 个图像
【发布时间】:2020-02-14 08:24:03
【问题描述】:

我需要为列表视图项添加两个以上的图像,并且我知道我只能使用两个列表:StateImageList 以及通过设置 ImageIndex 和 StateImageIndex 的 Large 或 SmallImageLists。 是否有可能在同一个列表视图项(同一列)上添加两个以上的图像。

谢谢!

【问题讨论】:

  • 我相信你必须拥有列表视图。
  • 您要并排放置 2 张图片吗?根据组合的数量,您可以以编程方式绘制新图像来显示您需要的组合并制作一个大列表?我回答了一个类似的问题(尽管它是如何在 ObjectListView 中做到这一点,它是基本列表视图的开源替代方案)。 stackoverflow.com/a/58114167/4824531

标签: 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);
                }
            }

【讨论】:

    猜你喜欢
    • 2011-03-07
    • 1970-01-01
    • 2018-06-05
    • 2015-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-04
    • 1970-01-01
    相关资源
    最近更新 更多