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.
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);
}
If I were you I would use a ListView
instead because displaying the icon with a listview is much easier.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.