Techno World Inc - The Best Technical Encyclopedia Online!

THE TECHNO CLUB [ TECHNOWORLDINC.COM ] => C/C++/C# => Topic started by: Admin on December 27, 2006, 12:55:36 AM



Title: Load an Icon from an Embedded Resource in .NET
Post by: Admin on December 27, 2006, 12:55:36 AM
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:

Code:
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.