The code given below works fine. The only problem is mouse wheel/keyup cannot be used after the TOP image is displayed, it fills the keyboard buffer. Then I have to wait awhile to use wheel/keydown. Also the images after wheel/keydown goes beyond last image. It should stop at the last image like it stops at the first image. Code courtesy of Geek On Demand.
Private Sub Images_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.Image = ImageList1.Images.Item(increaseCount(count))
End Sub
Private Sub Images_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseWheel
Try
If e.Delta > 0 Then
PictureBox1.Image = ImageList1.Images.Item(decreaseCount(count))
ElseIf e.Delta < 0 Then
PictureBox1.Image = ImageList1.Images.Item(increaseCount(count))
End If
Catch ex As Exception
End Try
End Sub
Private Sub Images_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Try
If e.KeyCode = Keys.Down Then
PictureBox1.Image = ImageList1.Images.Item(increaseCount(count))
End If
Catch ex As Exception
End Try
End Sub
Private Sub Images_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
Try
If e.KeyCode = Keys.Up Then
PictureBox1.Image = ImageList1.Images.Item(decreaseCount(count))
End If
Catch ex As Exception
End Try
End Sub
Private Function increaseCount(ByRef count As Integer) As Integer
count += 1
If count + 1 > ImageList1.Images.Count Then
count = 0
End If
Return count
End Function
Private Function decreaseCount(ByRef count As Integer) As Integer
count -= 1
If count - 1 > ImageList1.Images.Count Then
count = 0
End If
Return count
End Function
You can modify the decrease count function as :