473,320 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 28605
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Andreas Neudecker | last post by:
Hi. I know you can read the filename of a program as sys.argv. But what about modules? Is there a similar way to find out the file name of a module (called by some other module or program) from...
7
by: Jon Davis | last post by:
http://support.microsoft.com/default.aspx?scid=kb;en-us;329014 Adding the code at this URL results in an error message: An unhandled exception of type...
1
by: D. Yates | last post by:
Hi, I am looking for an example of how to extract bitmap images from an embedded resource file (a file with *.res extension, which can be viewed inside of the ide and can hold bitmaps, icons,...
0
by: Sanjay Tibrewal | last post by:
Hello, I am trying out a piece of code I downloaded from a link on msdn site. It's a server menu generating control that I tried to add to my custom control assembly. I was able to compile the...
0
by: Tracy | last post by:
I have an question regarding to an visual basic .net resource file. It kept complaining about the line : " Me.grdRevenues.Images.Add(CType(resources.GetObject("resource"), System.Drawing.Image))...
0
by: Agnes | last post by:
I got 6 resource file name label.en-US.resx, label.zh-CN.resx.. etc some file is fail to open and I got the following error "The container cannot be disposed at design time". What's hapend ??...
0
by: gopal | last post by:
Hi, I had an issue with loading/using resource file. I thought i will share this information if it helpful some . I have a console C# application and inside this i have class definition as...
8
by: John Dunn | last post by:
Since currently we aren't allowed to have compiled XAML files embedded in C++ apps I'm using Markup::XamlReader::Load to dynamically load XAML files. This works perfectly fine with external files...
2
by: steve | last post by:
I have the following routine for retrieving error message strigs from a resource file which is embedded in the project. But when it is called I get the error messsage "Could not find any...
0
by: raylopez99 | last post by:
I have a minor problem locating an image file to load as a Bitmap. A resource file "NudeSusan.jpeg" (which I think is actually a bmp file, originally taken from a jpeg of model Susan Spears) is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.