Reputation: 899
I've tried finding the solution but to no avail. I believe what i want is string concatenation...
I have a variable "pictureid=face2"
in my resources folder i have a picture called "face2.jpg"
.
On the form i have a picture box.
This is the code I cant get to work
pictureBox1.Image = Properties.Resources.(pictureid + ".jpg");
Where am i going wrong? The error says there is an identifier expected.
Upvotes: 0
Views: 2859
Reputation:
Image
expects an Image or a descendant thereof (Bitmap and Metafile objects), which you can use as you coded, if you add the image to your project resources (edit: I should clarify - to do this, go to Project > Properties > Resources tab and "Add Resource". Don't just drop it in the folder):
pictureBox1.Image = Properties.Resources.face2;
If you don't want to include the image in your project, you can use ImageLocation, which will accept a string rather than an object:
pictureBox1.ImageLocation = pictureid + ".jpg"; //assuming you include it in the same folder as the exe
You could also do something like this:
Image face2 = Image.FromFile(pictureid + ".jpg");
pictureBox1.Image = face2;
Upvotes: 1