MapWinGIS:SampleCode-VB Net:SublcassMouseWheel

This is a back-up of the WIKI.
Not all links might work
We're working on a new wiki.

Main Page | Recent changes | View source | Page history | Log in / create account |

Printable version | Disclaimers | Privacy policy

The Class

 ' This class illustrates how to expose the MouseWheel event on the AxMap control
 ' This class was created by Ted Dunsford on April 28, 2008
 Public Class MouseWheelMap
     Inherits AxMapWinGIS.AxMap
 
     Public Const WM_MOUSEWHEEL As Integer = &H20A
     Public Const MK_LBUTTON As Integer = &H1
     Public Const MK_RBUTTON As Integer = &H2
     Public Const MK_MBUTTON As Integer = &H10
 
     ' This is the event that should be intercepted to receive the mouse wheel event
     Public Event mwMouseWheel(ByVal sender As Object, ByVal e As MouseEventArgs)
 
     ' This method traps all windows messages, but only responds to the MouseWheel message
     Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
         If m.Msg = WM_MOUSEWHEEL Then
 
             Dim xpos, ypos, mouseKeys, rotation, delta As Integer
             xpos = m.LParam.ToInt32() And 65535
             ypos = m.LParam.ToInt32() / 65536
             mouseKeys = m.WParam.ToInt32() And 65535
             rotation = m.WParam.ToInt32() / 65536
             delta = rotation / 120
             Dim mb As MouseButtons
             Select Case mouseKeys
                 Case MK_LBUTTON : mb = Windows.Forms.MouseButtons.Left
                 Case MK_RBUTTON : mb = Windows.Forms.MouseButtons.Right
                 Case MK_MBUTTON : mb = Windows.Forms.MouseButtons.Middle
                 Case Else : mb = Windows.Forms.MouseButtons.None
             End Select
 
             RaiseEvent mwMouseWheel(Me, New MouseEventArgs(mb, 0, xpos, ypos, delta))
 
         End If
 
         MyBase.WndProc(m)
     End Sub
 
 End Class

Using The Class

 Public Class Form1
 
     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
         Dim mwMap As New MouseWheelMap
         mwMap.Parent = Me
         mwMap.Dock = DockStyle.Fill
         AddHandler mwMap.mwMouseWheel, AddressOf mwMap_MouseMove
     End Sub
 
     Private Sub mwMap_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
         MessageBox.Show(e.Delta.ToString())
     End Sub
 End Class

Posted by Ted Dunsford on April 29, 2008

Retrieved from "http://mapwindow.org/wiki/index.php/MapWinGIS:SampleCode-VB_Net:SublcassMouseWheel"

This page has been accessed 1,567 times. This page was last modified on 29 April 2008, at 16:35.