2012-03-27 36 views
1

我的问题是我需要更改鼠标指针在MouseMove事件中的位置,这会导致无限递归。我需要禁止Me.Cursor.Position = newpos生成的MouseMove事件。我怎样才能做到这一点?如何在特定情况下抑制MouseMove事件?

我阅读了关于Me.EnableEvents = False但这对于Visual Studio 2005无效,我找不到相应的。

回答

0

你究竟想要做什么?也许有更好的方法。但是,假设这是您想要的,您可以在使用RemoveHandler更改光标位置之前取消订阅MouseMove事件中的事件处理程序。刚刚完成时将其添加回去:

Public Class MyForm 

    Private Sub MyForm_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _ 
      Handles Me.MouseMove 

     UnsubscribeEvents() 

     ' change mouse pointer's position here... 

     ResubscribeEvents() 
    End Sub 

    Private Sub UnsubscribeEvents() 
     RemoveHandler Me.MouseMove, AddressOf MyForm_MouseMove 
    End Sub 

    Private Sub ResubscribeEvents() 
     AddHandler Me.MouseMove, AddressOf MyForm_MouseMove 
    End Sub 

End Class