none
Working with the mouse wheel in VB 2019 RRS feed

  • Question

  • Has anyone got a solution for scrolling side way with the mouse wheel at the runtime? Ive found an addin (SideScroller) in Marketplace (https://marketplace.visualstudio.com) but only works in editor... :(
    Friday, November 22, 2019 1:18 PM

All replies

  • Hi

    I have one application where I use the MouseWheelTilt for horizontal scrolling. Been a while since I delved into this code but here it is. Obviously, it will not be likely to suit your needs as it is specific to the needs I had at the time. There are references to various general variables which are associated with the configuration of the use of the MouseWheel. Vertical Scroll is also included for completeness.

    	MustInherit Class Win32Messages
    		Public Const WM_MOUSEHWHEELTILT As Integer = &H20E '526
    	End Class
    	Protected Overrides Sub WndProc(ByRef m As Message)
    		If sw.ElapsedMilliseconds > My.Settings.TrackSense Then
    			Select Case m.Msg
    				Case Win32Messages.WM_MOUSEHWHEELTILT
    					sw.Restart()
    					FireMouseHWheelTilt(CInt(m.WParam))
    					Exit Sub
    			End Select
    		End If
    		MyBase.WndProc(m)
    	End Sub
    	Private Sub FireMouseHWheelTilt(s As Integer)
    		If s > 0 Then
    			Dim v As Integer = HS.Value + My.Settings.WheelTilt * 60 * My.Settings.GridScale
    			If v <= HS.Maximum Then
    				HS.Value += My.Settings.WheelTilt * 60 * My.Settings.GridScale
    			Else
    				HS.Value = HS.Maximum
    			End If
    			sw.Restart()
    		End If
    		If s < 0 Then
    			Dim v As Integer = HS.Value - My.Settings.WheelTilt * 60 * My.Settings.GridScale
    			If v > 0 Then
    
    				HS.Value -= My.Settings.WheelTilt * 60 * My.Settings.GridScale
    			Else
    				HS.Value = 0
    			End If
    			sw.Restart()
    		End If
    	End Sub
    	Private Sub Form1_MouseWheel(sender As Object, e As MouseEventArgs) Handles Me.MouseWheel
    		If sw.ElapsedMilliseconds > My.Settings.VSsense Then
    			Dim ss As Integer = My.Settings.VSstep * CInt(My.Settings.GridFnt.GetHeight + My.Settings.GridVgap)
    			Select Case e.Delta > 0
    				Case False
    					Dim v As Integer = VS.Value + ss
    					If v <= VS.Maximum - Panel2.DisplayRectangle.Height Then
    						VS.Value = v
    					Else
    						Try
    							VS.Value = VS.Maximum - Panel2.DisplayRectangle.Height
    						Catch ex As Exception
    						End Try
    					End If
    				Case Else
    					Dim v As Integer = VS.Value - ss
    					If v > 0 Then
    						VS.Value = v
    					Else
    						VS.Value = 0
    					End If
    			End Select
    			sw.Restart()
    		End If
    	End Sub


    Regards Les, Livingston, Scotland

    Friday, November 22, 2019 1:59 PM