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

4
我在GUI应用程序中有几个图标存储在ImageList中。我想从这个列表中设置通知图标,但问题是它只接受Icon实例而不是Image。
System.Windows.Forms.NotifyIcon trayIcon = ...;
System.Windows.Forms.ImageList notifierImageList = ...;

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

感谢您的选择。
1个回答

9

下面有几个选项。

  1. 不要将图标存储在ImageList中,而是将其存储为资源。然后从资源构建Icon对象。

  2. 通过创建句柄将图像转换为图标。我在网上找到了这个方法。

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接