2 Replies - 727 Views - Last Post: 15 September 2012 - 06:29 PM Rate Topic: -----

#1 brickman619  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-September 12

How to make a picture box change picture on click, and back again?

Posted 15 September 2012 - 03:37 PM

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.
Is This A Good Question/Topic? 0
  • +

Replies To: How to make a picture box change picture on click, and back again?

#2 torind_2000  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 55
  • View blog
  • Posts: 284
  • Joined: 22-August 11

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

    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
Was This Post Helpful? 0
  • +
  • -

#3 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

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

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1