Home > DeveloperSection > Forums > Change two images in one picture box using a button (VB.NET)
Mark Devid
Mark Devid

Total Post:101

Points:707
Posted on    April-05-2013 1:41 AM

 ASP.NET MVC ASP.NET MVC 
Ratings:


 2 Reply(s)
 2695  View(s)
Rate this:
Hi Everyone!

I've been trying to change the image in a picture box. It works if I want to change it with one image, but I can't get it to change to the other image. It 

should alternate between the two images when I click the button.

Here is my code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)  Handles Button1.Click

    Dim num As Boolean
    If num = False Then
        PictureBox3.Image = My.Resources.Beep
        num = True
    Else
        PictureBox3.Image = My.Resources.Skateboard
        num = False

    End If
End Sub

I've been trying to figure out why it doesn't work for a long time, any help wouldbe appreciated.

Thanks in advance!


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    April-05-2013 8:16 AM

Hi Mark!

Use button_click event as below

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)  Handles Button1.Click

    Dim Shared num As Boolean
    If num = False Then
        PictureBox3.Image = My.Resources.Beep
        num = True
    Else
        PictureBox3.Image = My.Resources.Skateboard
        num = False
    End If
End Sub
Class level option

I hope it resolve your problem 

Vijay Shukla

Total Post:100

Points:700
Posted on    April-05-2013 8:23 AM

Hi Mark!

You can try as below

Dim num As Boolean

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)  Handles Button1.Click

   If num = False Then
       PictureBox3.Image = My.Resources.Beep
       num = True
   Else
       PictureBox3.Image = My.Resources.Skateboard
       num = False
End If

End Sub

Don't want to miss updates? Please click the below button!

Follow MindStick