gpt4 book ai didi

c# - 如何在 ListView 的图像列表中添加系统图标

转载 作者:太空宇宙 更新时间:2023-11-03 13:49:15 24 4
gpt4 key购买 nike

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

我的问题是:

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

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

//lv.ImageIndex = 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);

关于c# - 如何在 ListView 的图像列表中添加系统图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14215307/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com