WPF - See Application Icon in Code

I added an icon to my WPF application in the project properties.

How can I refer to this icon to add it to the NotifyIcon I am creating for the system tray.

In the code, which is?

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

      

Does not work. Malcolm

+1


source to share


2 answers


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;

      



+6


source


I think this might be what you are looking for:

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



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

+2


source







All Articles