469,303 Members | 2,066 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,303 developers. It's quick & easy.

Find an image in a resource file by name

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?

Jul 27 '07 #1
3 27223
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");
*******************************************

ti*****@gmail.com wrote:
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?
Jul 27 '07 #2
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

<ti*****@gmail.comwrote in message
news:11**********************@q75g2000hsh.googlegr oups.com...
>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?

Jul 27 '07 #3
On Jul 27, 11:33 pm, timn...@gmail.com wrote:
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();

Jul 29 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Andreas Neudecker | last post: by
7 posts views Thread by Jon Davis | last post: by
1 post views Thread by D. Yates | last post: by
reply views Thread by gopal | last post: by
2 posts views Thread by steve | last post: by
reply views Thread by raylopez99 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.