C# 为什么WPF NotifyIcon图标属性设置程序会引发异常?

C# 为什么WPF NotifyIcon图标属性设置程序会引发异常?,c#,wpf,notifyicon,C#,Wpf,Notifyicon,我在WPF中遇到NotifyIcon问题,第二行抛出异常。我似乎找不到使用参考资料中的图标文件的方法,有人能帮忙吗 notifyI = new NotifyIcon(); notifyI.Icon = new Icon("Power.ico"); notifyI.Text = "Shutdown Timer"; notifyI.Visible = true; notifyI.MouseDoubleClick += new System.Windows.Forms.MouseEventHandle

我在WPF中遇到NotifyIcon问题,第二行抛出异常。我似乎找不到使用参考资料中的图标文件的方法,有人能帮忙吗

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);
图标(字符串)构造函数在磁盘上查找图标文件的文件,而不在资源中查找。考虑使用图标(流)构造函数代替.< /P> 或者使用Project+属性、资源选项卡、添加资源按钮上的箭头、添加现有文件。选择你的.ico文件。然后你会这样使用它:

 notifyI.Icon = Properties.Resources.Power;

它抛出了什么异常?在我的例子中是FileNotFoundException。下面的答案为我整理好了。