【问题标题】:Display running Process Icons in ListView在 ListView 中显示正在运行的进程图标
【发布时间】:2013-03-05 10:53:20
【问题描述】:

我是编程新手,所以如果我问了一些愚蠢的问题或使用了错误的术语,我提前道歉。 我正在尝试查找所有正在运行的进程(如在任务管理器中,“应用程序”)并在 ListView 中用图标列出它们。

我一直在四处寻找,发现了很多关于此的问答,但我很难让它发挥作用。

这是我确定出错的部分:

ImageList imageListSmall = new ImageList();
Icon ico = Icon.ExtractAssociatedIcon(theprocess.MainModule.FileName);
imageListSmall.Images.Add(ico);
lvAppProg.SmallImageList = imageListSmall;


ListViewItem itemProcess = new ListViewItem(theprocess.ProcessName);
itemProcess.SubItems.Add(theprocess.Id.ToString());
lvAppProg.Items.AddRange(new ListViewItem[] {itemProcess});

我正在尝试列出每个进程及其 ID 和图标,据我了解,我需要做的就是创建一个“ImageList”,提取目标“进程”的图标位置,然后添加小图像图标到带有进程名称和 ID 的 ListView。 (不知道图标是否需要在单独的列中) 非常感谢任何帮助!

谢谢! :)

【问题讨论】:

    标签: c# listview process icons taskmanager


    【解决方案1】:

    您必须将 Imagelist 分配给 ListViewItem 并将 imageindex 设置为:

    ListViewItem itemProcess = new ListViewItem(theprocess.ProcessName);
    itemProcess.SubItems.Add(theprocess.Id.ToString());
    lvAppProg.Items.AddRange(new ListViewItem[] {itemProcess});
    itemProcess.ImageList = imageListSmall;
    itemProcess.ImageIndex = YOURIMAGEINDEX
    

    【讨论】:

    • 感谢您的快速回复。 itemProcess.ImageList = imageListSmall;我在 Visual Studio 中收到此错误。 “无法将属性或索引器‘System.Windows.Forms.ListViewItem.ImageList’分配给——它是只读的”
    • 哦。好的。比你必须在 ListView 上设置 ImageList-Property。也可以看看stackoverflow.com/questions/6312473/…
    • 非常感谢您的帮助!当我添加这一行时,我实际上发现了一个新错误: Icon ico = Icon.ExtractAssociatedIcon(theprocess.MainModule.FileName);我的一些进程从列表视图中消失了……我不明白。
    猜你喜欢
    • 2013-09-13
    • 2023-04-08
    • 2011-06-03
    • 1970-01-01
    • 2010-09-17
    • 1970-01-01
    • 2016-11-09
    • 2014-08-15
    • 1970-01-01
    相关资源
    最近更新 更多