我是编程新手,所以如果我问一些愚蠢的事情或使用错误的术语,我会道歉。 我正在尝试查找所有正在运行的进程(如在任务管理器中,"应用程序")并使用图标在ListView中列出它们。
我一直在四处寻找并发现很多关于这个的Q& A但是我很难让它运转起来。
这是我确定它出错的部分:
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”,提取目标“Process”的图标位置,然后添加小图像icon使用进程名称和ID到ListView。 (我不知道图标是否需要在一个单独的列中) 非常感谢任何帮助!
谢谢! :)
答案 0 :(得分: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