Resources

P

Paul Cheetham

Hi,

I am developing a Windows Form app, that has graphical buttons.
Obviously I use the same button more than once throuout the application,
but Visual Studio would appear to embed a set of images for each button
into the program resources, instead of using a commen one.

If I can make it use a common copy, I could reduce the size of my final
exe file quite considerably.

Is there a way I can edit this, and what is the best way to do it?

Thanks.

Paul
 
B

Bob Powell [MVP]

You can embed one copy of the button and then get that from the resources
using GetManifestResourceStream.

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

Ramuseco Limited .NET consulting
http://www.ramuseco.com

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.
 
P

Paul Cheetham

Thanks Bob.

I'm not sure how to edit the resources in a .net project though. (Mine
is in VB.Net) - Good old fashioned Win32 apps were fine, but does VS.Net
have a resource editor?

Thankyou.

Paul
 
B

Bob Powell [MVP]

Resources come in two flavours. Either stored in a resx file or just added
to the solution and set as "embedded resource" in the build action
properties.

For your application it's probably just as easy to do the latter.

Add a resource to the solution, change the build action setting, retrieve it
useing the following:

Image.FromStream(me.GetType().Assembly.GetManifestResourceStream("myapp.Bitmap1.bmp"))

Note that the actual name you use depends upon the root namespace, whether
the resource is in a folder and other factors. If you can't deduce the fully
qualified name to use from your solution structure and namespace etc you can
put a bit of debug code in to help you. This can be removed later but it
lists all the resources for you so you can pick up the right one:

Dim resname As String
For Each resname in me.GetType().Assembly.GetManifestResourceNames
System.Disagnostics.Trace.WriteLine(resname)
Next

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

Ramuseco Limited .NET consulting
http://www.ramuseco.com

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.
 

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