Im working on a program in VB 2012. I want to make it so that when a picture box is clicked, its picture changes to another picture. When its clicked again, its picture changes back to the original.
2 Replies - 330 Views - Last Post: 15 September 2012 - 06:29 PM
#1
How to make a picture box change picture on click, and back again?
Posted 15 September 2012 - 03:37 PM
Replies To: How to make a picture box change picture on click, and back again?
#2
Re: How to make a picture box change picture on click, and back again?
Posted 15 September 2012 - 05:26 PM
you do it with the click event
something like
this isn't exactly what you're looking for, but it's a start
something like
Private Sub PictureBox1_Click(sender As Object, e As System.EventArgs) Handles PictureBox1.Click
PictureBox1.Image = New Bitmap("c:\Users\Public\Pictures\Sample Pictures\hydrangeas.jpg")
End Sub
Private Sub MainForm_Load(sender As Object, e As System.EventArgs) Handles Me.Load
PictureBox1.Image = New Bitmap("C:\Users\Public\Pictures\Sample Pictures\tulips.jpg")
End Sub
Private Sub PictureBox1_MouseDoubleClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDoubleClick
PictureBox1.Image = New Bitmap("C:\Users\Public\Pictures\Sample Pictures\tulips.jpg")
this isn't exactly what you're looking for, but it's a start
#3
Re: How to make a picture box change picture on click, and back again?
Posted 15 September 2012 - 06:29 PM
I've done something similar using the tag property of the picturebox.
at design time, I set the tag to 0
Then in the Click event of the picturebox I used
so with each click the tag is so that the next click is the opposite image.
at design time, I set the tag to 0
Then in the Click event of the picturebox I used
If pbToggle.Tag.ToString = "0" then 'Set the image to the one you want on the initial click pbToggle.Tag = "1" 'now set the tag to 1 so the next picture shows on next click Else 'Set the image to the other picture pbToggle.Tag = "0" End If
so with each click the tag is so that the next click is the opposite image.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|