הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Tuesday, November 22, 2011 9:36 PM
I want to change a picture in a if statement. The picture is in a picture box.
I tried:
if picturebox1.image=myresouces.grass.jpg then
picturebox1.image=myresources.picture.jpg
else
end if
Please help,
Thanks
All replies (3)
Wednesday, November 23, 2011 1:04 AM ✅Answered | 1 vote
You can't compare one image to another like that. You will need to keep track of the image in the picturebox for yourself. Create a global variable (a string type is suitable) so you can use code like this:
Dim CurrentImage As String = "Grass"
...
If CurrentImage = "Grass" Then
PictureBox1.Image = My.Resources.Clouds
CurrentImage = "Clouds"
ElseIf CurrentImage = "Clouds" Then
PictureBox1.Image = My.Resources.Grass
CurrentImage = "Grass"
End If
Wednesday, November 23, 2011 12:20 AM | 1 vote
You should use a Bitmap if you want to change images and also do not want to lock the file that is behind the PictureBox image...particularly if you intend to make changes to it.
Tuesday, December 20, 2011 10:36 PM
Thanks Acamar,
That helped me very much.