Search code examples
c#wpfwinformssystem.drawing

System.Drawing.Icon path


I made a WPF Application and I want to use a NotifyIcon, so I added a reference to System.Windows.Forms and to System.Drawing. I'm using the following code:

System.Windows.Application.Current.MainWindow.Hide();

NotifyIcon Tray = new NotifyIcon();
Tray.Icon = new System.Drawing.Icon("Assets/Icons/icon.ico");
Tray.Visible = true;
Tray.MouseDoubleClick += (s, e) => 
{
    System.Windows.Application.Current.MainWindow.Show();
    System.Windows.Application.Current.MainWindow.WindowState = WindowState.Normal;
};

My problem is in the fourth line because the function expects a system path, but I want to add a path to an icon included in my project.

How do I refer to a file in my Project with Windows Drawing Icons?


Solution

  • Set the Build Action property of the icon included in your project to Content, and the Copy to Output Directory property to Copy if newer. Then your current code should work provided that the path is valid.