473,416 Members | 1,869 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,416 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 28662
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.