Custom Search

Saturday, December 24, 2005

How To Load an Embedded Resource in C#

1) Add an Embedded Resource in your C# Project (ex: image1.bmp);
2) In your code use this call to load the Bitmap :

Bitmap image = new Bitmap(GetType().Module.Assembly.
GetManifestResourceStream("MyApplicationNamespace.image1.bmp"));

GetManifestResourceStream("ApplicationNamespace.
ResourceFileWithExtension").
or
GetManifestResourceStream("ApplicationNamespace.FolderName.
ResourceFileWithExtension").
Depending where the Resource File is located in your project.

Embedded Resource in C#, Bitmap sample

To Embedded a Bitmap as Resource in C# project:

1) Add existing file in your project (ex: bitmap file);
2) Select the new added file;
3) Set the Build Action to "Embedded Resource" in the properties Panel.