1

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

Malcolm
  • 12,524
  • 28
  • 89
  • 125

2 Answers2

9
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;
Stanislav Kniazev
  • 5,386
  • 3
  • 35
  • 44
2

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.

Community
  • 1
  • 1
Ben McIntosh
  • 1,532
  • 3
  • 20
  • 29