简体   繁体   中英

How can I load NotifyIcon from Resources using C#

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.NotifyIcon or use some convert?

Thank you for your help.

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;

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM