I have a frame with a picture within it, and I am able to do the mouse scroll with the code below, but when i scroll with the mouse there are no limits so the picture seems like it could scroll through for eternity. What am I missing? Also with this it diables my scrollbar usage the code for that is below the asterix'.

Option Explicit

Private Const PM_REMOVE = &H1

Private Type POINTAPI
    X As Long
    Y As Long
End Type

Private Type Msg
    hWnd As Long
    Message As Long
    wParam As Long
    lParam As Long
    time As Long
    pt As POINTAPI
End Type

Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Private Declare Function WaitMessage Lib "user32" () As Long
Private bCancel As Boolean
Private Const WM_MOUSEWHEEL = 522
Private Sub ProcessMessages()

Dim Message As Msg

Do While Not bCancel
    If PeekMessage(Message, Me.hWnd, WM_MOUSEWHEEL, WM_MOUSEWHEEL, PM_REMOVE) Then
        If Message.wParam < 0 Then 
            Picture1.Top = Picture1.Top + 240 'scrolls up
            Picture1.Top = Picture1.Top - 240 'scrolls down
        End If
    End If

End Sub
Private Sub Form_Load()

Picture1.AutoRedraw = True
Picture1.Print "Please use  mouse wheel To move this Picture."

End Sub
Private Sub Form_Unload(Cancel As Integer)

bCancel = True

End Sub


'also in the Form_load
    Picture1.AutoSize = True
    Picture1.Top = 0
    Picture1.Left = 0
    Picture1.Width = fraScrollBox.Width
    VScroll1.Top = fraScrollBox.Top
    VScroll1.Left = fraScrollBox.Left + fraScrollBox.Width
    VScroll1.Height = fraScrollBox.Height
    VScroll1.Min = 0
    VScroll1.Max = Picture1.Height - fraScrollBox.Height
    VScroll1.SmallChange = 1500
    VScroll1.LargeChange = 2500

Private Sub VScroll1_Change()
    Picture1.Top = VScroll1.Value * -1
End Sub
9 Years
Discussion Span
Last Post by selvaganapathy

Check the condition that Picturebox1.Top is positive. if it is negative, it will be top of the frame. Dont let the PictureBox1.Top to negative. Similarly dont let the PictureBox1.Top + PictureBox1.Height greater than fraScrollBox.Height

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.