我在 GUI 应用程序的 ImageList 中有几个图标。我想从此列表中设置通知图标,但问题是它只接受图标实例而不接受图像。
System.Windows.Forms.NotifyIcon trayIcon = ...;
System.Windows.Forms.ImageList notifierImageList = ...;
trayIcon.Icon = notifierImageList.Images[0]; //This fails since no such cast exist
谢谢。
最佳答案
这里有几个选项。
您可以将图标存储为资源,而不是将图标存储在 ImageList 中。然后从资源构造一个图标对象。
通过创建句柄将图像转换为图标。这个是我在网上找的。
notifyIcon1.Icon = Icon.FromHandle(((Bitmap)imageList1.Images[0]).GetHicon());
关于c# - 如何设置将 ImageList 中的图像转换为图标类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6666763/