如何设置将ImageList中的图像转换为图标类型?

时间:2011-07-12 15:27:49

标签: c# winforms image icons

我在GUI应用程序的ImageList中有一些图标。我想从此列表中设置通知图标,但问题是它只接受图标实例而不是图像。

System.Windows.Forms.NotifyIcon trayIcon = ...;
System.Windows.Forms.ImageList notifierImageList = ...;

trayIcon.Icon = notifierImageList.Images[0]; //This fails since no such cast exist

感谢。

1 个答案:

答案 0 :(得分:7)

以下是几个选项。

  1. 您可以将其存储为资源,而不是将图标存储在ImageList中。然后从资源构造一个Icon对象。

  2. 通过创建句柄将图像转换为图标。这是我在网上找到的。

    notifyIcon1.Icon = Icon.FromHandle(((Bitmap)imageList1.Images[0]).GetHicon());

相关问题