views:

287

answers:

1

Hi everyone.

I'm having trouble with a NotifyIcon in WPF

I currently have the following:

                    notifyI = new NotifyIcon();
                    notifyI.Icon = new Icon("Power.ico");
                    notifyI.Text = "Shutdown Timer";
                    notifyI.Visible = true;
                    notifyI.MouseDoubleClick += new
                    System.Windows.Forms.MouseEventHandler(notifyI_MouseDoubleClick);

The thing is the notifyI.Icon = new Icon("Power.ico") is keep throwing and exception. I can't seem to find a way to use the icon file I have in the resources, can anyone help.

Thanks, I am using VS2010 and Blend 3.

+4  A: 

The Icon(string) constructor looks for a file on disk for the icon file, it doesn't look in a resource. Consider using the Icon(Stream) constructor instead.

Or use Project + Properties, Resource tab, arrow on Add Resource button, Add Existing File. Select your .ico file. Then you'd use it like this:

 notifyI.Icon = Properties.Resources.Power;
Hans Passant