How to Create a BMP Resource

V

vijaynats

Hi

I created a simple Windows Control using C#. To change the Display Icon
(picture) for the control in the Toolbox i added a 16x16 bmp and marked
it as "Embedded Resource".

The problem is how to declare this bmp as a resouce and use it in the
project.

The "Resouce View" in VS.NET 2003 shows blank and on right
click..nothing is shown. Neither does right clicking on the Project
provide any "Add Resouce.." option.

I created a .rc file and right clicking on that also is of no use.

Please let me know how i can turn this bmp as a resouce for my control.

Thanks

Vijay
 
W

Wiktor Zychla

I created a simple Windows Control using C#. To change the Display Icon
(picture) for the control in the Toolbox i added a 16x16 bmp and marked
it as "Embedded Resource".

The problem is how to declare this bmp as a resouce and use it in the
project.

The "Resouce View" in VS.NET 2003 shows blank and on right
click..nothing is shown. Neither does right clicking on the Project
provide any "Add Resouce.." option.

I created a .rc file and right clicking on that also is of no use.

Please let me know how i can turn this bmp as a resouce for my control.

there are two distinct types of resources: win32 resources and .net
resources. if you add a file as a .net resource (embedded resource) it is
not visible as win32 resource (that's why you do not see it in resource
view).

to programatically extract the bitmap from .net resources use following
snippet:

Assembly a = Assembly.GetExecutingAssembly();
Stream s = a.GetManifestResourceStream( "__name_of_default_namespace__" +
nameofFileToExtract );
Bitmap b = new Bitmap( s );

Wiktor Zychla
 
B

Bob Powell [MVP]

In addition to Wiktor's advice you might want to look at the article in
Windows Forms Tips and Tricks that explains this process.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
V

vijaynats

Hi again,
All i want is a custom bmp in the toolbox for a custom control that i
create. I guess no programming is needed to do this. Plz let me know
how to get the custom bmp.

Thanks

Vijay
 
W

WRH

Hello
Not sure want you want but have you done this..

Project->Add Existing Item and add the .bmp file to
your project

Right click the file name in the Solution Explorer panel
and select propertes. Change the Build Action property
to Embedded.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top