C# 如何在 ListBox 中显示带有图标的进程 [英] C# How to Display Processes with Icons in ListBox
本文介绍了C# 如何在 ListBox 中显示带有图标的进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个应用程序,当按下按钮时,它会列出当前正在运行的进程,并在它们旁边显示它们的图标.
I am creating an application where when a button is pressed, it will a list of currently running processes, with their icons right beside them.
private void materialFlatButton6_Click_1(object sender, EventArgs e)
{
Process[] process = Process.GetProcesses();
foreach (Process prs in process)
{
listBox1.Items.Add(prs.ProcessName + " (" + prs.PrivateMemorySize64.ToString() + ")");
}
}
这是当前存在的代码,它执行此操作.
This is the current code present and it does this.
但我希望它像这样显示.
But I want it to show up like this.
我将如何用 ListBox 显示图标?
How would I present the icons with the ListBox?
推荐答案
这里是获取进程关联图标的方法:
Here is how to get the associated icon of the process:
Process[] processes = Process.GetProcesses();
foreach(var thisProcess in processes)
{
Icon ico = Icon.ExtractAssociatedIcon(thisProcess.MainModule.FileName);
}
如果我是你,我会使用 ListView
代替,因为显示带有 listview 更容易.
If I were you I would use a ListView
instead because displaying the icon with a listview is much easier.
这篇关于C# 如何在 ListBox 中显示带有图标的进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文