-
Aug 30th, 2014, 06:55 AM
#1
Thread Starter
Hyperactive Member
RESOLVED [VB2010] Set a image depending from a String value
I have about 100 little images (A1, A2,..., B1, B2,....) in Project/Resources
My goal is to set a PicturBox.Image depending from the value of a MyImage as String variable.
Obviously I can do:
Code:
Select Case MyImage
Case "A1"
PictureBox.Image = My.Resources.A1
Case "A2"
PictureBox.Image = My.Resources.A2
...................................
but this mean to make a Select Case of 100 items....
Question: is there a way to set directly the image from MyString, something like:
PictureBox.Image = My.Resources.MyString ??
Ty
Last edited by phil2000; Aug 30th, 2014 at 11:26 AM.
-
Aug 30th, 2014, 08:02 AM
#2
Re: [VB2010] Set a image depending from a String value
I haven't tried it, but a quick Google search suggests something like this should work:
Code:
My.Resources.ResourceManager.GetObject(MyImage)
-
Aug 30th, 2014, 08:04 AM
#3
Re: [VB2010] Set a image depending from a String value
try this:
Code:
PictureBox1.Image = DirectCast(My.Resources.ResourceManager.GetObject(MyImage), Bitmap)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 30th, 2014, 08:06 AM
#4
Re: [VB2010] Set a image depending from a String value
@paulg4ije...
you nearly beat me there
My.Resources.ResourceManager.GetObject(MyImage) returns an object and needs to be cast to either bitmap or image
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 30th, 2014, 08:10 AM
#5
Re: [VB2010] Set a image depending from a String value
Originally Posted by .paul.
@paulg4ije...
you nearly beat me there
My.Resources.ResourceManager.GetObject(MyImage) returns an object and needs to be cast to either bitmap or image
Sounds good to me
-
Aug 30th, 2014, 11:26 AM
#6
Thread Starter
Hyperactive Member
Re: [VB2010] Set a image depending from a String value
Originally Posted by .paul.
try this:
Code:
PictureBox1.Image = DirectCast(My.Resources.ResourceManager.GetObject(MyImage), Bitmap)
It works perfectly!!
Ty
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|