Frage

Hi i have some parser error when im trying to add icon to NotifyIcon. This one works fine:

System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon();

ni.Icon = new System.Drawing.Icon("C:\\Users\\Daniel\\Documents\\Visual Studio
2012\\Projects\\Pies\\Pies\\main.ico");

But when I'm trying to do it in this way:

ni.Icon = new System.Drawing.Icon("main.ico");

It returns some strange ParserError. I added main.ico to the project. When im adding images in xaml I'm just using "/image/image.jpg" but this don't want to work in this way. Do yuo know why ?

War es hilfreich?

Lösung

Notice, that you are trying to use WinForms control in WPF project. And icon class from WinForms doesn't support pack URIs.

Since you want to store your image in your assembly, you can't get it as WinForms Icon easily. WPF usually works with ImageSource class and you can convert it to WF icon (How can I convert BitmapImage to Icon?), but I would call it pain.

NotifyIcon is not implemented in WPF, so I suggest to try this solution.

More detais: Can I use NotifyIcon in WPF?

Andere Tipps

Why don't you add the .ico file in your solution and point the reference to it something like this

Try doing this

ni.Icon = new System.Drawing.Icon(@"pack://application:,,,/Icon/main.ico");
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top