Link to home
Create AccountLog in
Visual Basic Classic

Visual Basic Classic

--

Questions

--

Followers

Top Experts

Avatar of Wilder1626
Wilder1626🇨🇦

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

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Martin LissMartin Liss🇺🇸

What do you mean by "scroll into Picture2"?

Avatar of Wilder1626Wilder1626🇨🇦

ASKER

Into the picture2, i will have multiple controls in it and i would like to scroll PictureBox using the mouse wheel.

Avatar of Martin LissMartin Liss🇺🇸

It looks to me like you are already scrolling picture2. what do you want to do differently?

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of Martin LissMartin Liss🇺🇸

Oh, never mind. I understand.

Avatar of Martin LissMartin Liss🇺🇸

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

Avatar of aikimarkaikimark🇺🇸

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?

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Martin LissMartin Liss🇺🇸

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

Avatar of Wilder1626Wilder1626🇨🇦

ASKER

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 LissMartin Liss🇺🇸

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of Martin LissMartin Liss🇺🇸

I edited my previous post.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


SOLUTION
Avatar of aikimarkaikimark🇺🇸

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.

Avatar of Wilder1626Wilder1626🇨🇦

ASKER

Thanks a lot for your help. Everything is working the way i like it.

Avatar of Martin LissMartin Liss🇺🇸

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
Visual Basic Classic

Visual Basic Classic

--

Questions

--

Followers

Top Experts

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.