Question PictureBox images -change image on _click

mattbro

New member
Joined
Mar 20, 2010
Messages
2
Programming Experience
Beginner
Hi. I'm using VB.net '08 express and I have a form in a program with a picturebox. I have a series of images in My.Resources. What I am trying to do is get the images in the box to change in sequence whenever the button is clicked. So far, code reads;

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sequence As Integer
Select Case sequence
Case 1
PictureBox1.Image = My.Resources._55
sequence = sequence + 1
Case 2
PictureBox1.Image = My.Resources._56
sequence = sequence + 1
Case 3
PictureBox1.Image = My.Resources._57
sequence = sequence + 1
End Select
End Sub

When the button is clicked, the 1st image appears and the button then does nothing. If anyone has any ideas, I would be grateful.
 
You can use a Static variable to cycle through each case every time the button is clicked.

Here is an example. Just substitute your picturebox images for the label:

VB.NET:
   Private Sub btnCycle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCycle.Click
        Static x As Integer
        x = x + 1               'increment static counter
        If x = 5 Then x = 1 'reassign starting value to counter
        Select Case x
            Case 1
                lblOnOff.BackColor = Color.Red
                lblOnOff.Text = "RED"
            Case 2
                lblOnOff.BackColor = Color.Yellow
                lblOnOff.Text = "YELLOW"
            Case 3
                lblOnOff.BackColor = Color.CornflowerBlue
                lblOnOff.Text = "BLUE"
            Case 4
                lblOnOff.BackColor = Color.MediumSpringGreen
                lblOnOff.Text = "GREEN"
        End Select
    End Sub
 
Back
Top