Hi can somebody help me. This is my coding for button Next and Previous but when I click on next it just goes to next like from pictures 1 and 2 to pic 3 and 4 but not any more because i have pictures in two imagelist upto 20 but it doesnt work and the coding for button previous also doesnt work same problem.

Next Button Coding

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        Static imagenumber As Integer
            Try
            imagenumber -= 1
                imageNumber = 0
            If imageNumber = 0 Or imageNumber < 0 Then
                imageNumber = ++1
                PictureBox1.Image = ImageList1.Images(imageNumber)
                PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
            End If
                imageNumber += 1
                imageNumber = 0
            If imageNumber > 0 Or imageNumber = 0 Then
                imageNumber = ++1
                PictureBox1.Image = ImageList1.Images(imageNumber)
                PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
                imageNumber -= 1
                imageNumber = 0
                If imageNumber = 0 Or imageNumber < 0 Then
                    imageNumber = ++1
                    PictureBox2.Image = ImageList2.Images(imageNumber)
                    PictureBox2.SizeMode = PictureBoxSizeMode.StretchImage
                End If
                imageNumber += 1
                imageNumber = 0
                If imageNumber > 0 Or imageNumber = 0 Then
                    imageNumber = ++1
                    PictureBox2.Image = ImageList2.Images(imageNumber)
                    PictureBox2.SizeMode = PictureBoxSizeMode.StretchImage
                End If
            End If

            Catch ex As Exception
                MsgBox(ex.Message)
            End Try

        End Sub

Previous Button coding

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

            Try

            If Not imageNumber > 0 Then
                imageNumber = --1
                PictureBox1.Image = ImageList1.Images(imageNumber)
                PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
            End If


            If Not imageNumber > 0 Then
                imageNumber = --1
                PictureBox2.Image = ImageList2.Images(imageNumber)
                PictureBox2.SizeMode = PictureBoxSizeMode.StretchImage
            End If

            Catch ex As Exception
        End Try
        End Sub

Edited 5 Years Ago by prince87: n/a

See if this helps.

Public Class Form1
    Private iImageNumber As Integer = 0 '// for images Index in ImageLists.

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '// set .SizeMode once.
        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
        PictureBox2.SizeMode = PictureBoxSizeMode.StretchImage
        setImages() '// set images to PictureBoxes if needed.
        '// for testing.
        Button1.Text = "Previous" : Button2.Text = "Next"
    End Sub

    '// btnPrevious.
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '// check if Not first image Then subtract -1, Else set # for last Image if wanting to loop thru images.
        If Not iImageNumber = 0 Then iImageNumber -= 1 Else iImageNumber = ImageList1.Images.Count - 1
        '// used ImageList1.Images.Count since both PictureBoxes seem to work with the same amount of images and no need to check both ImageLists.
        setImages()
    End Sub

    '// btnNext.
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        '// check if Not last image Then add +1, Else set # for first Image if wanting to loop thru images.
        If Not iImageNumber = ImageList1.Images.Count - 1 Then iImageNumber += 1 Else iImageNumber = 0
        setImages()
    End Sub

    Private Sub setImages()
        PictureBox1.Image = ImageList1.Images(iImageNumber)
        PictureBox2.Image = ImageList2.Images(iImageNumber)
    End Sub
End Class
Comments
I love the way you have coded.

Thank You Friend You sort out my problem . it working now........

Edited 5 Years Ago by prince87: n/a

This question has already been answered. Start a new discussion instead.