Changing MouseWheelMode if control key pressed

Example requests & Code samples for GdPicture Toolkits.
Post Reply
tnorwood
Posts: 4
Joined: Thu Apr 19, 2012 6:07 pm

Changing MouseWheelMode if control key pressed

Post by tnorwood » Fri Apr 27, 2012 5:42 pm

In GDViewer, how can I force the MouseWheelMode to be MouseWheelModeVerticalScroll if I use the mouse wheel alone, but MouseWheelModeZoom if I use the mouse wheel with the control key pressed?

I tried using the ViewerMouseWheel event, but it does not indicate whether the control key is pressed or not.

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Changing MouseWheelMode if control key pressed

Post by Loïc » Mon Apr 30, 2012 5:39 pm

Hello,

I do not really understand what you are trying to do. Could you clarify ?

Thank you for any hint.

Kind regards,

Loïc

tnorwood
Posts: 4
Joined: Thu Apr 19, 2012 6:07 pm

Re: Changing MouseWheelMode if control key pressed

Post by tnorwood » Mon Apr 30, 2012 5:47 pm

I want the GDViewer to scroll when I use the mouse wheel, but when I press CTRL + mouse wheel, I want it to zoom. I want it to have the same behavior as most Microsoft products, which allow you to scroll with the mouse wheel alone, and zoom with CTRL + mouse wheel.

I have been able to use the ViewerKeyUp and ViewerKeyDown events to change the mode from MouseWheelModeVerticalScroll to MouseWheelModeZoom when the user presses the Control key, but I am finding that these events don't fire every time. They only seem to work when I fit the image to the viewer using SetZoomFitViewer.

Let me know if you need any more information.

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Changing MouseWheelMode if control key pressed

Post by Loïc » Tue May 01, 2012 9:17 pm

Hello,

OK it's not so hard to do.

Please turn false the EnableMouseWheel property. And the catch KeyDown, KeyUp & MouseWheel events as following:

Code: Select all

   Private m_CtrlKeyDown As Boolean

    Private Sub GdViewer1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles GdViewer1.MouseWheel
        If m_CtrlKeyDown Then
            If e.Delta > 0 Then
                GdViewer1.ZoomIN()
            Else
                GdViewer1.ZoomOUT()
            End If
        Else
            If e.Delta < 0 Then
                GdViewer1.SetVScrollBarPosition(GdViewer1.GetVScrollBarPosition + GdViewer1.ScrollLargeChange)
            Else
                GdViewer1.SetVScrollBarPosition(GdViewer1.GetVScrollBarPosition - GdViewer1.ScrollLargeChange)
            End If
        End If

    End Sub

    Private Sub GdViewer1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles GdViewer1.KeyDown
        m_CtrlKeyDown = e.Control
    End Sub

    Private Sub GdViewer1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles GdViewer1.KeyUp
        m_CtrlKeyDown = False
    End Sub
Hope this helps!

Kind regards,

Loïc

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest