<p>I have a .ico file that is embedded as a resource (build action set to resource).  I am trying to create a NotifyIcon.  How can I reference my icon?</p>

<pre><code>notifyIcon = new NotifyIcon();
notifyIcon.Icon = ??     // my icon file is called MyIcon.ico and is embedded
</code></pre>

[{'answer_id': 74671, 'author': 'user13125', 'author_id': 13125, 'author_profile': 'https://Stackoverflow.com/users/13125', 'pm_score': 8, 'selected': True, 'text': '<p>Your icon file should be added to one of your project assemblies and its Build Action should be set to Resource. After adding a reference to the assembly, you can create a NotifyIcon like this:</p>\n\n<pre><code>System.Windows.Forms.NotifyIcon icon = new System.Windows.Forms.NotifyIcon();\nStream iconStream = Application.GetResourceStream( new Uri( "pack://application:,,,/YourReferencedAssembly;component/YourPossibleSubFolder/YourResourceFile.ico" )).Stream;\nicon.Icon = new System.Drawing.Icon( iconStream );\n</code></pre>\n'}, {'answer_id': 74679, 'author': 'Jaykul', 'author_id': 8718, 'author_profile': 'https://Stackoverflow.com/users/8718', 'pm_score': 4, 'selected': False, 'text': '<p>Well, you don\'t want to use the resx style resources: you just stick the ico file in your project in a folder (lets say "ArtWork") and in the properties, set the Build Action to "Resources" ...</p>\n\n<p>Then you can reference it in XAML using PACK URIs ... "pack://application:,,,/Artwork/Notify.ico"</p>\n\n<p>See here: <a href="http://msdn.microsoft.com/en-us/library/aa970069.aspx#Programming_with_Pack_URIs" rel="noreferrer">http://msdn.microsoft.com/en-us/library/aa970069.aspx</a> and the <a href="http://msdn.microsoft.com/en-us/library/aa972152.aspx" rel="noreferrer">sample</a></p>\n\n<p>If you want to be a little bit more ... WPF-like, you should look into the <a href="http://www.codeplex.com/wpfcontrib/Wiki/View.aspx?title=NotifyIcon&amp;referringTitle=Home" rel="noreferrer">WPF Contrib</a> project on CodePlex which has a NotifyIcon control which you can create in XAML and which uses standard WPF menus (so you can stick "anything" in the menu).</p>\n'}, {'answer_id': 75049, 'author': 'shinybluesphere', 'author_id': 10282, 'author_profile': 'https://Stackoverflow.com/users/10282', 'pm_score': 2, 'selected': False, 'text': '<p>I created a project here and used an embedded resource (build action was set to Embedded Resource, rather than just resource). This solution doesn\'t work with Resource, but you may be able to manipulate it. I put this on the OnIntialized() but it doesn\'t have to go there.</p>\n\n<pre><code>//IconTest = namespace; exclamic.ico = resource \nSystem.IO.Stream stream = this.GetType().Assembly.GetManifestResourceStream("IconTest.Resources.exclamic.ico");\n\n   if (stream != null)\n   {\n       //Decode the icon from the stream and set the first frame to the BitmapSource\n       BitmapDecoder decoder = IconBitmapDecoder.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.None);\n       BitmapSource source = decoder.Frames[0];\n\n       //set the source of your image\n       image.Source = source;\n    }\n</code></pre>\n'}, {'answer_id': 1870823, 'author': 'Thomas Bratt', 'author_id': 15985, 'author_profile': 'https://Stackoverflow.com/users/15985', 'pm_score': 5, 'selected': False, 'text': '<p>A common usage pattern is to have the notify icon the same as the main window\'s icon.  The icon is defined as a PNG file.</p>\n\n<p>To do this, add the image to the project\'s resources and then use as follows:</p>\n\n<pre><code>var iconHandle  = MyNamespace.Properties.Resources.MyImage.GetHicon();\nthis.notifyIcon.Icon = System.Drawing.Icon.FromHandle(iconHandle);\n</code></pre>\n\n<p>In the window XAML:</p>\n\n<pre><code>&lt;Window x:Class="MyNamespace.Window1"\nxmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\nxmlns:local="clr-namespace:Seahorse"\nxmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"\nHeight="600"\nIcon="images\\MyImage.png"&gt;\n</code></pre>\n'}, {'answer_id': 32081321, 'author': 'Mike Sage', 'author_id': 862414, 'author_profile': 'https://Stackoverflow.com/users/862414', 'pm_score': 2, 'selected': False, 'text': '<p>If you are just looking for the simple answer, I think this is it where MyApp is your application name and where that\'s the root namespace name for your application.  You have to use the pack URI syntax, but it doesn\'t have to be that complicated to pull an icon out of your embedded resources.  </p>\n\n<pre><code>    &lt;Window x:Class="MyApp.MainWindow"\n    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\n    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"\n    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"\n    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"\n    mc:Ignorable="d"\n    Height="100"\n    Width="200"\n    Icon="pack://application:,,,/MyApp;component/Resources/small_icon.ico"&gt;\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/74466', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3047/']