[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to read resource file

Posted on 2006-03-22
8
Medium Priority
?
535 Views
Last Modified: 2008-01-09
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

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

0
Comment
Question by:tolgaong
8 Comments
 
LVL 16

Expert Comment

by:Swapnil Piparia
ID: 16256713
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.

Regards,
NetSwap
0
 
LVL 6

Expert Comment

by:hatem72
ID: 16260509
0
 
LVL 9

Author Comment

by:tolgaong
ID: 16266696
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Author Comment

by:tolgaong
ID: 16308753
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 ;)

0
 
LVL 16

Expert Comment

by:Swapnil Piparia
ID: 16308814
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

Regards,
NetSwap.
0
 
LVL 9

Author Comment

by:tolgaong
ID: 16319360
I'm sorry but I really cannot achive to work it. :(
0
 
LVL 1

Accepted Solution

by:
scfindy earned 2000 total points
ID: 16346219
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
           Get
                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
0
 
LVL 9

Author Comment

by:tolgaong
ID: 16370413
That's what I'm looking for.

Thanks very much.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question