
Including Resources in .exe
Originally published on my old blog at cumps.be on February 27, 2004.
As a reply to my Non-Rectangular Form article, someone asked if you couldn’t include the bitmap in the file.
Well, you can. And that is what this little article will talk about. This very little article.
When do you want to include things? If they are small and are vital for your app to run. This bitmap is vital! You could also include icons for example…
How do you do it?
Include your bitmap in your project. Go to its properties and for ‘Build Action’ choose ‘Embedded Resource’. This will compile your file into your .exe as a resource.
This was what we had to load our bitmap:
FileStream imageStream = File.OpenRead("Glass.bmp");
Bitmap imageBackground = (Bitmap)Bitmap.FromStream(imageStream);
Now it’s:
Bitmap imageBackground = new Bitmap(this.GetType(), "Glass.bmp");
That’s it. Wasn’t that simple? Your Bitmap is inside the .exe and it’s loading fine.
I’ve uploaded this version as well.
Note: You can drag the .exe around and press ‘q’ to close it (for the people who haven’t read the Non-Rectangular Form article; imagine having to kill it ;))
You May Also Like

Associating Your Program with Every File: ShellExtension
A C# class that adds your program to the right-click menu of every file, by writing a shell command key under HKEY_CURRENT_USER.

C# Script
CS-Script: a small tool that compiles and runs a single .cs file in memory, like a batch script for C#.

Non-Rectangular Form
Turning any bitmap into a non-rectangular Windows Form in C#: build a Region from every non-transparent pixel.



