Malcolm
Malcolm

Reputation: 12864

WPF - Refer to app icon in code

i have added an icon to a WPF app in the project properties.

How do I refer to that icon so I can add it to a NotifyIcon that I am creating for system tray.

In code that is??

  System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon();
  ni.Icon = new System.Drawing.Icon("MyIcon.ico");

Does not work. Malcolm

Upvotes: 1

Views: 6485

Answers (2)

Stanislav Kniazev
Stanislav Kniazev

Reputation: 5488

System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon();
ni.Icon = System.Drawing.Icon.ExtractAssociatedIcon(
             System.Reflection.Assembly.GetEntryAssembly().ManifestModule.Name);
ni.Visible = true;

Upvotes: 9

Ben McIntosh
Ben McIntosh

Reputation: 1552

I think this may be what you are looking for:

How do I use an icon that is a resource in WPF?

You need to embed the icon as a resource and then you can access it from code.

Upvotes: 2

Related Questions