0

I want load icon from Resources.

I am using code:

Resources.myImage

It is Bitmap.

I need:

System.Windows.Forms.NotifyIcon.

How can I load image like a System.Windows.Forms.NotifyIconor use some convert?

Thank you for your help.

chelocre
  • 73
  • 1
  • 2
  • 9

3 Answers3

3

Sounds like you are trying to set the image of the NotifyIcon. NotifyIcon is a WinForm control. When you drag it onto your Form you are basically creating an instance of the NotifyIcon class which has several properties.

One of the properties of the NotifyIcon control is called Icon which lets you set the icon that gets displayed in the notification area. Generally you can set this straight from the IDE but if you are trying to set it programmatically using a .ico file you have in your resources then you can do the following:

this.notifyIcon1.Icon = MyProjectName.Properties.Resources.MyIconName;
Dmitry K.
  • 972
  • 6
  • 16
  • Thank you for your replye, but when I try your code. I get error: `Cannot implicitly convert type 'System.Drawing.Bitmap' to 'System.Drawing.Icon'` – chelocre Apr 26 '16 at 16:50
  • Whats the extension of the file you have in your resources? It should be .ico. If its not you need to convert it. There are plenty of online converters that can easily do that for you. – Dmitry K. Apr 26 '16 at 16:51
  • It is `.ico`, I put component from tool bar and set image in icon properties and work nice. Thank you. – chelocre Apr 26 '16 at 16:53
1

NotifyIcon is the class to show an icon on the tray, not the icon per se.

NotifyIcon has a property named Icon, that's what you want to set, create a new NotifyIcon and then set it's Icon property to the resource.

Also, remember Icon is of type "Icon", not "Bitmap", you need a .ico file.

Gusman
  • 14,905
  • 2
  • 34
  • 50
1

If you want to use the System.Windows.Forms.NotifyIcon, you have to set the icon first. You could use one of the ones in SystemIcons, for example: var myInformationIcon = SystemIcons.Information; If u want to use your own icons u have to convert your bitmap to an .ico-file.

Convert a Bitmap to an Icon with C#, have a look at this example Bitmap_to_Icon

Dave Wijnen
  • 71
  • 2
  • 7