Load an Icon from an Embedded Resource in .NET

Posted December 9, 2006 by johnnythawte in C programming

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.