Load an Icon from an Embedded Resource in .NET

When you are developing a Windows Forms application in .NET, it’s not immediately obvious how to programatically load an icon file embedded in your executable. This recipe shows you the 1 line solution.


Your icon file should be a regular windows icon file. Add it to your project, and in the properties for the icon make sure that it is set to Embedded Resource.

Now in your code, add the following line:
Icon theIcon = new Icon(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MyNameSpace.Filename.ico"));

Replace “MyNameSpace” with the namespace of your application, and replace “Filename” with the name of your icon file.

You should now be able to use the icon directly in any windows control that uses icons, like the NotifyIcon control.

The Conversation

Follow the reactions below and share your own thoughts.

4 Responses to “Load an Icon from an Embedded Resource in .NET”

  1. May 24, 2009 at 9:37 pm, Kaminda said:

    G8 Thanks, It saved me very valuble time. Cheers

    Reply

  2. June 30, 2010 at 5:58 pm, Hossrod said:

    I ran into one hiccup that took me a while to figure out, but if the icons are in a sub-folder, you need to include the name in the namespace.

    For example, if Filename.ico was in a folder called Icons, it would be reffrenced as “MyNameSpace.Icons.Filename.ico”.

    Reply

  3. September 14, 2010 at 4:56 pm, Tom said:

    Icon ico = Properties.Resources.ICONNAME;

    8P

    Reply

  4. February 11, 2012 at 8:39 am, keddy said:

    thanks Tom

    Reply

Leave a Reply