Hi,
How can I load a resources file like a picture with a variable?
Example that not work:
VB Code:
Me.PictureBox1.Image = My.Resources.MyVariable
Printable View
Hi,
How can I load a resources file like a picture with a variable?
Example that not work:
VB Code:
Me.PictureBox1.Image = My.Resources.MyVariable
use LoadResPicture ( rsrcIndex, 0)
where rsrcIndex is the name of the pic in your resource file
use LoadResPicture ( rsrcIndex, 0)
where rsrcIndex is the name of the pic in your resource file
How have you created this resource in the first place? Are you using VB 2005 (please, please, please specify in future)? Have you added the image via the Resources tab of the project properties? Did you add it as an Image resource? If the last three answers were Yes then the code you provided will work, which suggests that that is not what you did.
Hi,
I am using Microsoft Visual Basic 2005 Express Edition.
Yes, the three answers are yes.
I have five pictures in my resources tab:
_01 _02 _03 _04 _05
I would strongly suggest that you use descriptive names for everything. Giving anything a name like _01 is never an asset. If you've add an Image resource named _01 to your project via the resources tab then to display it in a PictureBox you would use:That's exactly what I used in the attached screenshot and you can see the image displayed. You said that that code you posted earlier didn't work. What does that mean? Did the code execute but you didn't see the image? Did your app throw an exception? Did your computer explode?VB Code:
myPictureBox.Image = My.Resources._01
Hi,
This what I am try to do:
NumPicture = NumPicture + 1
MyVariable = Format(NumPic, "00")
Me.PictureBox1.Image = My.Resources.MyVariable
I get this error:
MyVariable is not a member of Resources
You simply cannot do stuff like that. Do a search on the forum for "reflection" and see how many times it's been posted that a string is not an identifier and an identifier is not a string and if you want to use a string to refer to a type member then you have to use reflection. If you want to use numbers to identify things then put the objects in an array or a collection and use the number as an index.