How to read resource file

Hi everyone,
I'm using VS2005.

I've added a pictrure to the resource file.
And show it on the button

The default way to set the image is:
dynpSplitButton.Image = global::Health_Proc.Properties.Resources.AO;

However, I want to set the name AO dynamiccaly,

I mean, I need a function which takes a vairable and returns me the image/object

dim img as string = "AO"
dynpSplitButton.Image = global::Health_Proc.Properties.Resources.getResourceByName(img) <= This function is imaginary.

Who is Participating?
I added the following to the the .vb file that was automatically created for my resource files:

Public Shared ReadOnly Property Image(ByVal ImageName As String) As System.Drawing.Bitmap
                Dim obj As Object = ResourceManager.GetObject(ImageName, resourceCulture)
                Return CType(obj, System.Drawing.Bitmap)
            End Get
End Property

You can then access the images with the following:

YadaYada.Image = my.Resources.NameOfYourResources.Image("NameOfImage")

Good luck, Steve
SwapnilSoftware ArchitectCommented:
Hi tolgaong,

you can get string from resource (.resx) file by

dim resourceCulture as System.Globalization.CultureInfo
dim str as string = System.Resources.ResourceManager.GetString("EventLogEntryHeaderTemplate", resourceCulture)

here "EventLogEntryHeaderTemplate" means your key from this you can get msg.

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

tolgaongAuthor Commented:
I think the above solutions are not suitable for me.
I have some other urgent jobs for today.

I'll try to rephare my question again tomorrow afternoon.
Thanks for your participation.
tolgaongAuthor Commented:
I'm back again. Sorry for the so late return.

Let's do it step by step
1) Create a new VB.NET project
2) Click "Show All files"
3) Expand My Project
4) Select Resources.resx
5) Right click and select "Open"
6) Select Images from the toolbar (Left upper drop down button)
7) Select Add Existing File from Add Resource (Next to the previous button) [I've added the zapotec file from c:\windows]
8) Select and double click to form1 (to create form_load event)
9) Write: PictureBox1.Image = Global.ResourceFile.My.Resources.Zapotec
10) Run. It works.

What I want is to get the file name as a string
For example:
11) Put a textbox and a button to the form.
12) comment the page_load event
13) Suppose that the user entered "Zapotec" to the textbox and entered the button.

I want to load the file if it is in the resources.

I really need this.
To netswap:
You wrote:
dim resourceCulture as System.Globalization.CultureInfo
dim str as string = System.Resources.ResourceManager.GetString("EventLogEntryHeaderTemplate", resourceCulture)

When I past it to the designer, I couldn't see the GetString method. Actually, I need a getImage function ;)

SwapnilSoftware ArchitectCommented:
Hi tolgaong,

see following code (taken from hatem72's link, it works)

 make a ResourceManager, as an assembly-ignorant ResourceManager through the
' CreateFileBasedResourceManager method. Simply specify the name of the resources
' file, and the location. The single "." indicates that the current directory should
' be searched the null indicates to use the default resourceset
Dim rm As ResourceManager = CreateFileBasedResourceManager( "Greeting", ".", null)

' having got a reference to the resources, retrieve specific strings...
' Note that the CASE MATTERS
rm.GetStream("Greeting") <-- for image kind of thing
rm.GetString("PasswordException") <-- for text

tolgaongAuthor Commented:
I'm sorry but I really cannot achive to work it. :(
tolgaongAuthor Commented:
That's what I'm looking for.

Thanks very much.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.