【问题标题】:How to add system icons in an imagelist in a listview如何在列表视图的图像列表中添加系统图标
【发布时间】:2012-12-22 07:47:54
【问题描述】:

我通过在列表视图中使用此代码在imageList 中添加了图标。现在我希望在显示某个目录的列表视图时显示它们。

我的问题是:

我需要对imagelist1 控件进行哪些更改?以及如何在代码中调用imagelist1

imageList1.Images.Add(
    BlackFox.Win32.Icons.IconFromExtensionShell(
        ".*", 
        BlackFox.Win32.Icons.SystemIconSize.Small));

//lv.ImageIndex = 1;

【问题讨论】:

  • 这个“黑狐”是谁?
  • 它是从中检索系统子的类。
  • 当我将它用作 picturebox.image.add(BlackFox.Win32.Icons.IconFromExtensionShell(".zip", BlackFox.Win32.Icons.SystemIconSize.Small));它显示了 zip 图标
  • 我想知道是否可以以相同的方式将其添加到图像列表中。当显示文件列表时,我会得到带有它们的图标

标签: c# winforms listview imagelist


【解决方案1】:

如果我理解正确,您希望将 ImageList 中的图标与 ListView 中的相应文件一起显示。为此,您只需将 ListView 对象的 SmallImageListLargeImageList 属性指向 ImageList(取决于您的 ListView 使用的图标显示模式)。

private void UpdateListView() {
   ImageList IconList = new ImageList();

   IconList.Images.Add(
        BlackFox.Win32.Icons.IconFromExtensionShell(".*",
        BlackFox.Win32.Icons.SystemIconSize.Small));

   YourListview.SmallImageList = IconList;

   //Add the items to your Listview                

}

不要忘记将 ImageList 中的图标分配给 ListView 中的项目:

MyListItem.ImageIndex = 0;

MyListItem.ImageKey = "MyImageName";

或在添加 ListItems 时立即添加它们:

ListViewItem MyListItem= new ListViewItem("ItemName", "MyImageName");
ListViewItem MyListItem2= new ListViewItem("ItemName2", int ImageIndex);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多