Link to home
Start Free TrialLog in
Avatar of Wilder1626
Wilder1626Flag for Canada

asked on

VB6 - Scroll Mouse wheel on Picturebox

Hi,

I would like to  to scroll into Picture2 using my mouse wheel. So far i was using the VScroll1.

How can i do that?

Thanks for your help.

So far, i was doing:
Public Sub CheckKeyCode(KeyCode As Integer)
    Dim nScrollValue As Double
    Dim nOnePage As Integer
    
    nOnePage = Me.VScroll1.Height
    
    If KeyCode = vbKeyPageUp Or KeyCode = vbKeyPageDown Then
        If KeyCode = vbKeyPageDown Then
            nScrollValue = -Me.Picture2.Top + nOnePage
        Else
            nScrollValue = -Me.Picture2.Top - nOnePage
        End If


        If nScrollValue > Me.VScroll1.Max Then
            nScrollValue = Me.VScroll1.Max
            Me.Picture2.Top = -Me.VScroll1.Max
        End If
        If nScrollValue > 0 Then
            Me.VScroll1.Value = nScrollValue
        Else
            Me.VScroll1.Value = 0
        End If
    End If
    
End Sub

Private Sub Form_Load()

    VScroll1.Max = Picture2.Height - Picture1.Height
    
End Sub

Private Sub VScroll1_Scroll()
Picture2.Top = -(VScroll1.Value)
End Sub

Open in new window

mouse-scroll-wheel.zip
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

What do you mean by "scroll into Picture2"?
Avatar of Wilder1626

ASKER

Into the picture2, i will have multiple controls in it and i would like to scroll PictureBox using the mouse wheel.
It looks to me like you are already scrolling picture2. what do you want to do differently?
Oh, never mind. I understand.
OK, in order to do that you'll need to use subclassing (which is dangerous). Here's an example that I found on the web that scrolls a flexgrid. You can probably adapt it.
WheelHook-AllControls.zip
My approach would be like yours.  I've done this before, but not when I had a scroll wheel on my mouse.  If you make the vertical scroll bar the active control does your code work?
Attached is your project modified based on this EE solution. All the changes I made are marked with 'new. A word of caution and that is if you make code changes, save them often because if you press the "End" button in the IDE, VB6 will end without saving your changes.
28999029.zip
Let me try this Martin Liss.

aikimark, I would say that the scoll works but not the way I would like it to scroll.

Example, If i click inside the scroll bar, let's say in the middle of it, i would like to go straight to the middle of the picture.  I assume this is possible, but i was never able to do it.
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I edited my previous post.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks a lot for your help. Everything is working the way i like it.
You're welcome and I'm glad I was able to help.

If you expand the “Full Biography” section of my profile you'll find links to some articles I've written that may interest you.

Marty - Microsoft MVP 2009 to 2016
              Experts Exchange MVE 2015 and 2016
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2016