picturebox set picture

Silent77

Member
Joined
Oct 17, 2006
Messages
9
Programming Experience
Beginner
This is a pretty basic question but how do you define a pictureboxes picture in code?
 
The easiest way is to call the PictureBox's Load method and pass the path of the image file as a parameter. There are various ways though, so it really depends on your personal preference and also the circumstances, like where the image is coming from.
 
the picture is coming from the project. I added the picture file to the project through Add Existing Item. What I am trying to do is swap images when a radio button is clicked (more than one radio button and image).
 
ok I figured out from that code i can direct path the file but can i do it through the folder in the project "Resources" instead of direct path?
 
VB.NET:
Expand Collapse Copy
PictureBx.Image = My.Resources.imagefile
 
I put this in and it wont work.

VB.NET:
Expand Collapse Copy
[SIZE=2]PictureBox1.Image = [/SIZE][SIZE=2][COLOR=#0000ff]My[/COLOR][/SIZE][SIZE=2].Resources([/SIZE][SIZE=2][COLOR=#800000]"blue.jpg"[/COLOR][/SIZE][SIZE=2])
[/SIZE]

it says "App1.My.Resources' is a namespace and cannot be used as an expression. Any ideas on how to fix that?

Thanks for the help
 
It's probably like this:
VB.NET:
Expand Collapse Copy
PictureBx.Image = My.Resources.blue
or use ResourceManager
VB.NET:
Expand Collapse Copy
PictureBox1.Image = My.Resources.ResourceManager.GetObject("blue")
You can see in Resources tab of Application Properteis what name the object got.
 
The fact that you've added the image file to your project doesn't make it a resource. If you want to access an object via My.Resources then you need to go to the Resources tab of the project properties and add a new Image resource there. You may have already done that but nothing you posted so far indicates that it's so.
 
I put the images into the resource tab and called the images using
VB.NET:
Expand Collapse Copy
[SIZE=2]
PictureBox1.Image = [/SIZE][SIZE=2][COLOR=#0000ff]My[/COLOR][/SIZE][SIZE=2].Resources.ResourceManager.GetObject([/SIZE][SIZE=2][COLOR=#800000]"blue.JPG"[/COLOR][/SIZE][SIZE=2])
[/SIZE]
and it does not display an error or an image. Any ideas?
 
If you didn't put the image in the applications resources as jmcilhinney indicated then that is a good reason, also if you did put an image named 'blue.jpg' there the resource would in most cases be named just 'blue'. You must go to Application Properties, Resources tab and look at the 'Images' filter to see if it's there. If it's not there you must add it before getting it from there as you asked to do in post 5.
 
Back
Top