0

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
1
  • Basically a Is Nothing or End Sub has to be added at the end of first image.
    – Farook
    Jan 17, 2012 at 10:41

1 Answer 1

0

You can modify the decrease count function as :

Private Function decreaseCount(ByRef count As Integer) As Integer
 count -= 1
  If count - 1 > ImageList1.Images.Count Or count<0 Then
    count = 0
  End If
 Return count
End Function
7
  • Works perfectly and the navigation is much more smoother. If you're interested in continuing one more problem then I can describe it, or else I am posting a new problem adding images. In the UP method, when I reach the first image, it stops there. But on scroll down the images keep rolling beyond the last image.
    – Farook
    Jan 17, 2012 at 11:09
  • Geek FYI: stackoverflow.com/questions/8893639/…
    – Farook
    Jan 17, 2012 at 11:13
  • If you could pls answer my query.
    – Farook
    Jan 17, 2012 at 11:32
  • What is the query? The above query of image stops scrolling is solved I guess.
    – Harsh
    Jan 17, 2012 at 11:34
  • Geek! Try scrolling up. Scrolling stops at the first image-Good, you cannot scroll beyond this point-Good. Now try scrolling down, scrolling continues without a stop-This is the problem.
    – Farook
    Jan 17, 2012 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.