Assign a resource to a Picture Box programatically

  • Thread starter Thread starter Jürgen Heyn
  • Start date Start date
J

Jürgen Heyn

Good afternoon,

I would like to display a bitmap in a PictureBox which is stored in a
resource file.

The following code works perfectly:
picUser.Image = My.Resources.ResUserIcon01.x48_Crewmember

From a database the application retrieves a string:
"x48_Crewmember" (or "ResUserIcon01.x48_Crewmember")

How can I display the bitmap in a PictureBox using this string?

I could do ist with the following:
Select Case True
Case strBildname = "x48_Crewmember"
picUser.Image = My.Resources.ResUserIcon01.x48_Crewmember
....
End Select

Because of the number of bitmaps there must be a more elegant way.
Thank you for any hint.
Best regards
Jürgen Heyn, Wilhelmshaven, Germany
 
Hey,

Forgive me for bump, but I spent forever searching on google for this answer and could never find it. So I spent more time trying to figure it out for myself, and I have managed to do it!

Solution:

picuser.Image = My.Resources.ResourceManager.GetObject("RESOUCE NAME AS STRING")

Peace.
 
Hey,

Forgive me for bump, but I spent forever searching on google for this answer and could never find it. So I spent more time trying to figure it out for myself, and I have managed to do it!

Solution:

picuser.Image = My.Resources.ResourceManager.GetObject("RESOUCE NAME AS STRING")

Peace.
 
Hey,

Forgive me for bump, but I spent forever searching on google for this answer and could never find it. So I spent more time trying to figure it out for myself, and I have managed to do it!

Solution:

picuser.Image = My.Resources.ResourceManager.GetObject("RESOUCE NAME AS STRING")

Peace.
 
Thanks for this! I too spent many minutes trying to Google this, but unlike you I actually found your post so it saved me hours of possibly tedious work. :P
 
Good afternoon. I just signed up for this forum so I have never posted.
I have been trying to grab an image from resources and display at run time.


I am using Visual Studio 2015 and I have found the following code:

PictureBox1.Image = My.Resources.ResourceManager.GetObject("a4930956")

Where "a4930956" is the string name of the image contained in "Resources"

It does not work.

If I pull a text from my resources and message box it like so:

MsgBox (My.Resources.ResourceManager.GetObject("City"))

It works just fine and displays the name of the city entered in the file.

I have tried the image as a gif and also as a bitmap. No luck either way. it just shows up
as blank.

This code was all over the place when I googled it, so it looks like it should be correct,
yet I cannot get an image to display.

I am obviously missing something that is simply escaping me. I just don't get it and I
am pulling the hair out of my head.

Is there anyone out there that can help?

Many thanks for any input at all.
 
Back
Top