我从应用程序中提取了图标但是如何在列表视图中显示它
Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(@"C:\Program Files\Photoshop.exe");
我在图标变量中有图标,但我想在listview中显示它有什么办法吗?任何答案都将不胜感激。
答案 0 :(得分:4)
您可以通过Icon.ToBitmap()
方法将Icon
转换为Image
(因为Bitmap
来自Image
)。然后,只需创建一个包含图片的PictureBox
控件,并将其添加到ListView.Controls
集合中,如下所示:
// Get your image
var image = Icon.ExtractAssociatedIcon(@"C:\Program Files\Photoshop.exe").ToBitmap();
// Create a picture box to display in your ListView
var picture = new PictureBox()
{
Image = image,
Height = image.Height,
Width = image.Width
};
// Add this to your ListView
YourListView.Controls.Add(picture);