I have a few icons inside an ImageList in a GUI application. I want to set the notification icon from this list but the problem is it accepts only Icon instances not Image.
System.Windows.Forms.NotifyIcon trayIcon = ...;
System.Windows.Forms.ImageList notifierImageList = ...;
trayIcon.Icon = notifierImageList.Images[0]; //This fails since no such cast exist
Thanks.
Here is a couple of options.
Instead of storing the icon in an ImageList, you can store it as a resource. Then construct an Icon object from the resource.
Convert image to icon by creating a handle. This one I found on the web.
notifyIcon1.Icon = Icon.FromHandle(((Bitmap)imageList1.Images[0]).GetHicon());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With