2

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

我的问题是:

我需要做出哪些改变来imagelist1控制?以及如何调用imagelist1代码?

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

//lv.ImageIndex = 1;
4

1 回答 1

1

如果我理解正确,您希望将 ImageList 中的图标与 ListView 中的相应文件一起显示。为此,您只需将 ListView 对象的SmallImageListorLargeImageList属性指向 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);
于 2013-01-08T15:40:12.840 回答