We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

How to read resource file

tolgaong
tolgaong asked
on
Medium Priority
576 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.

Comment
Watch Question

SwapnilSoftware Architect
CERTIFIED EXPERT
Top Expert 2005

Commented:
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

Author

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.

Author

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 Architect
CERTIFIED EXPERT
Top Expert 2005

Commented:
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.

Author

Commented:
I'm sorry but I really cannot achive to work it. :(
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
That's what I'm looking for.

Thanks very much.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.