0

I want to add my icon as tay icon.

But this error is shown.

xaml.cs:

private System.Windows.Forms.NotifyIcon _notifyIcon; enter image description here

This icon already added on resources but not working.

When I writing codes then resources file name not be shown.

See:

enter image description here

How can I solve this problem?

Jim
  • 2,974
  • 2
  • 19
  • 29
Sabbir Ahmed
  • 59
  • 11
  • Possible duplicate of [How do I use an icon that is a resource in WPF?](http://stackoverflow.com/questions/74466/how-do-i-use-an-icon-that-is-a-resource-in-wpf) – Red Riding Hood Oct 29 '16 at 18:15
  • First, always show code instead of images. Second, it should work just fine as long as you added the icon trough the resource interface. – Jim Oct 29 '16 at 18:25

3 Answers3

1

You can use Stream

Stream iconStream = Application.GetResourceStream( 
            new Uri( "pack://application:,,,/YourReferencedAssembly;component/YourPossibleSubFolder/YourResourceFile.ico" )).Stream;
            notifyIcon.Icon = new System.Drawing.Icon(iconStream);
1

If you want to use it that way - don't add the image to the .resx file. Right click on the project -> Properties -> Resources -> Add Resource -> Add existing file... Add the image there. If you do this you should be able to get it in the code through Properties.Resources.MyIcon

SteppingRazor
  • 1,222
  • 1
  • 9
  • 25
  • 1
    *(You can just drag and drop the icon or image file in the resource window) will work just fine* – Jim Oct 29 '16 at 18:30
0

You just need to have an existing file, open the context menu on your folder , and then choose Add => Existing item...like this,name the folder Images

You need to change your image's property "Build Action" to Content and change the Copy to "If Newer" or "Always"

It will create a folder in bin\debug every time you build your application.

Then give your path like this @"Images\"

Arman
  • 45
  • 7