开发者

Why is WPF NotifyIcon Icon property setter throwing an exception?

开发者 https://www.devze.com 2023-01-01 06:33 出处:网络
I\'m having trouble with a NotifyIcon in WPF, the second line is throwing an exception. I can\'t seem to find a way to use the icon file I have in the resources, can anyone help.

I'm having trouble with a NotifyIcon in WPF, the second line is throwing an exception. I can't seem to find a way to use the icon file I have in the resources, can anyone help.

notifyI = new NotifyIcon();
notifyI.Icon = new Icon("Power.ico");
notifyI.Text = "Shutdown Timer";
notifyI.Visible = true;
notifyI.MouseDoubleClick += new
System.Windows.Forms.MouseEventHandler(notifyI_MouseDoubleCli开发者_开发问答ck);


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号