5,665,355 members and growing! (15,997 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » .NET Framework » How To     Intermediate License: The Code Project Open License (CPOL)

Embedding Multiple Icons into .NET Executables

By Ed.Poore

A brief walkthrough on how to embed multiple icons (and native resources) into a .NET executable.
C# 3.0, VB 8.0, VB 9.0, C# 2.0, C#, VBWindows, .NET, .NET 3.0, .NET 2.0, Win2K, WinXP, Win2003, Vista, WinForms, VS2005, Visual Studio, Dev

Posted: 12 Jul 2007
Updated: 12 Jul 2007
Views: 14,662
Bookmarked: 48 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
16 votes for this Article.
Popularity: 5.50 Rating: 4.57 out of 5
1 vote, 6.3%
1
0 votes, 0.0%
2
2 votes, 12.5%
3
3 votes, 18.8%
4
10 votes, 62.5%
5

Introduction

I have noticed in various (and lots of) places scattered all across the Internet, requests on how to embed multiple icons into a .NET executable, not embedded in the .NET resources (resx files) but accessible by the Windows Explorer and the like.

After chance comment on a page with nothing to do with the subject at hand, I realised that this capability is built into Visual Studio 2005. This article outlines the procedure required to compile multiple icons into an executable without having to resort to the command-line.

The Process

Step 1: The Resource File

For reasons that shall become apparent later, Visual Studio requires that the icons be compiled into a resource file. It is up to you how you generate this, but I shall use the designers with VS2005.

  1. Create a new "Native Resource Template" from the File | New dialog box.
  2. New Native Resource Template

  3. Right click anywhere in the designer, and select "Add Resource..." to reach the following dialog box:
  4. Import Resources Dialog Box

  5. You can, at this point, import any resources you wish to embed, but we will import some icons, so click "Import..." and select the icon files.
  6. Import File Dialog Box

    If you wish, you can change the ID associated with the resources in the Properties window.

  7. Now, we must save the resource template as a 32-bit Resource File. This is done via File | Save As..., making sure that "32-bit Resource File (*.res)" is selected in the "Save as type" box. Save it somewhere logical, e.g., in your project's directory.
  8. Saving the Resource File

Step 2: Compiling into the Executable

Visual Studio 2005 provides two ways of providing icons for .NET executables. One is via the Application Icon property in the Property pages. The second is via a resource file, and it is this method that we utilise.

  1. Open up the Application tab of the Properties page of your project.
  2. In the "Resources" group box, change the selection to point to Resource File, and browse for the resource file you just saved.
  3. Add Win32 Resource

Step 3: Compiling

Once the previous step has been completed, Visual Studio will now embed the Win32 resource into the executable when it compiles. To see the changes, simply recompile the application.

Multiple Icon Executable

You can see by the above screenshot that multiple icons have been embedded (natively) into the executable. Where this would be useful, for example, is if your application registers a file type, the files can have a different icon associated with them rather than the same as the executable. Or you won't have to distribute an icon file with your program, it can simply be embedded.

Summary

Hopefully, that has explained clearly enough how to accomplish the task of embedding multiple icons into a .NET executable without resorting to the command-line. If you have any suggestions for improvements / comments, don't hesitate to post them, I've probably made quite a few spelling mistakes along the way as well (no Intellisense).

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ed.Poore


Ed is a student who due to a form of cancer (now clear) took a year out before going to Imperial College, London to study Electronic Engineering.

His interests include shooting (clay-pigeon (shotgun), air-rifle and rifle), playing with his three labradors (Sandy, Rosie and Tundra), programming (most experienced in C# and C, although those are not the only ones), walking (has completed Gold Duke of Edinburgh's Award), playing games and reading.

He lives in two places on a 57 acre farm in West Waleswith the rest of the family during the holidays; and Greater London during term time.

Languages and Technologies: C#, C, VB6, VB.NET, XAML, (X)HTML, CSS, XSLT, Assembler (PIC), ASP.NET, WPF, Windows.Forms, ASP, VBScript, JavaScript, Pascal / Delphi, XML

Current Stuff:
1st Year MEng Electronics Engineering (Imperial College, London)
Occupation: Engineer
Company: PooreDesign
Location: United Kingdom United Kingdom

Other popular .NET Framework articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 15 of 15 (Total in Forum: 15) (Refresh)FirstPrevNext
GeneralGood Tutorialmemberctw3130:57 8 Nov '08  
GeneralRe: Good TutorialmemberEd.Poore11:42 8 Nov '08  
Answerfor Visual Studio 2008memberNevzatAdagide13:58 18 Oct '08  
QuestionRe: for Visual Studio 2008memberEd.Poore21:22 18 Oct '08  
GeneralImport of .res file not available in VS 2008membert_anjan9:23 11 Feb '08  
GeneralRe: Import of .res file not available in VS 2008memberEd.Poore9:50 11 Feb '08  
GeneralDoes not appear to work with 32-bit icons.memberIneffable10:43 1 Aug '07  
GeneralRe: Does not appear to work with 32-bit icons.memberEd.Poore14:23 1 Aug '07  
GeneralGood one!memberVasudevan Deepak Kumar0:26 13 Jul '07  
QuestionCan't add Win32 resource into VB.NET projectmemberProJee23:34 12 Jul '07  
AnswerRe: Can't add Win32 resource into VB.NET projectmemberChris Kolkman4:03 13 Jul '07  
GeneralInteresting...memberAnandChavali20:26 12 Jul '07  
GeneralRe: Interesting...memberEd.Poore1:51 13 Jul '07  
GeneralRe: Interesting...memberEd.Poore4:23 13 Jul '07  
GeneralNice OnememberPaul Conrad19:24 12 Jul '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 12 Jul 2007
Editor: Smitha Vijayan
Copyright 2007 by Ed.Poore
Everything else Copyright © CodeProject, 1999-2008
Web13 | Advertise on the Code Project