Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How set convert Images inside an ImageList to Icon Type?

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.

like image 559
Mehran Avatar asked Oct 28 '25 05:10

Mehran


1 Answers

Here is a couple of options.

  1. Instead of storing the icon in an ImageList, you can store it as a resource. Then construct an Icon object from the resource.

  2. Convert image to icon by creating a handle. This one I found on the web.

    notifyIcon1.Icon = Icon.FromHandle(((Bitmap)imageList1.Images[0]).GetHicon());
like image 190
Nick Alexeev Avatar answered Oct 29 '25 19:10

Nick Alexeev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!