Find an image in a resource file by name

  • Thread starter Thread starter timnels
  • Start date Start date
T

timnels

I have a bunch of images named head1, head2, head3... in my
Resources.resx file in my project. How do I get the image if I have
the name as a string?
 
Don't know if this helps, but this is how I get an icon file from my
resource file. I would imaging for an image it will be very similar,
probably only have to cast to a (Bitmap) instead of an (Icon).

Resx File: ProgramResources.resx

C# 2 Code:
*******************************************
using System.Resources;
using System.Reflection;

ResourceManager rm = new ResourceManager(
"YourProgramName.ProgramResources",
Assembly.GetExecutingAssembly());

Program.NotifyIcon.Icon =
(Icon)rm.GetObject("my_icon_name");
*******************************************
 
Hi

Look into the archives of this group a post I did a time ago with the code
for doing just that,
google "ignacio machin" resource
 
I have a bunch of images named head1, head2, head3... in my
Resources.resx file in my project. How do I get the image if I have
the name as a string?

here is my sample code using in a Winform App:

ResourceManager rm = new ResourceManager("ResourceReader.MyResource",
Assembly.GetExecutingAssembly());
resBox.Image = rm.GetObject("dotnet_logo") as Image;
rm.ReleaseAllResources();
 

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

Back
Top