ArcEngine的鼠标事件中按键判断~

我们都知道,在.Net的鼠标事件中判断鼠标事件方法如下(以button为例):

Private Sub Button1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            MsgBox("left_mouse clicked")
        ElseIf e.Button = Windows.Forms.MouseButtons.Middle Then
            MsgBox("middle_mouse clicked")
        ElseIf e.Button = Windows.Forms.MouseButtons.Right Then
            MsgBox("right_mouse clicked")
        End If
End Sub

 

在ArcEngine的AxMapControl1_OnMouseDown事件中我也仿照以上方法判断如下:

Private Sub AxMapControl1_OnMouseDown(ByVal sender As System.Object, ByVal e As ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent) Handles AxMapControl1.OnMouseDown

          If e.button = MouseButtons.Left  Then
            MsgBox("left_mouse clicked")

          End If

Exit Sub

结果提示警告:"通过实例访问共享成员,变量成员,枚举成员或嵌套类型;将不计算限定表达式"

警告的意思大概就是:共享成员(就像C++中的静态成员变量)不能通过实例访问,而应该用类直接访问

 

于是,修改如下:

Private Sub AxMapControl1_OnMouseDown(ByVal sender As System.Object, ByVal e As ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent) Handles AxMapControl1.OnMouseDown

          If e.button = Windows.Forms.MouseButtons.Left  Then
            MsgBox("left_mouse clicked")

          End If

Exit Sub

结果仍然有问题:


于是,我在该事件中将用msgbox观察e.button的数值到底是多少

结果按左键得到 1 , 按右键得到 2, 按中键得到 4 ,而非原先Windows.Forms.MouseButtons.Left(一个很大的六位数):

可见ArcEngine中鼠标事件中 鼠标按键判断 从.Net鼠标事件中 鼠标按键判断 继承而来,但作了修改

 

好了,AreEngine中正确的鼠标按键判断应该如下:

Private Sub AxMapControl1_OnMouseDown(ByVal sender As System.Object, ByVal e As ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent) Handles AxMapControl1.OnMouseDown

        If e.button = 1 Then
            MsgBox("left_mouse clicked")
        ElseIf e.button = 2 Then
            MsgBox("right_mouse clicked")
        ElseIf e.button = 4 Then
            MsgBox("middle_mouse clicked")
        End If

Exit Sub

 

你可能感兴趣的:(ArcEngine)