我的问题是我需要在MouseMove事件中更改鼠标指针的位置,这会导致无限递归。我需要抑制Me.Cursor.Position = newpos
生成的MouseMove事件。我怎么能这样做?
我阅读了Me.EnableEvents = False
,但这对Visual Studio 2005无效,我找不到相应的内容。
答案 0 :(得分:0)
你到底想要做什么?也许有更好的方法。但假设这是您想要的,您可以在使用MouseMove
更改光标位置之前取消订阅RemoveHandler
事件中的事件处理程序。只需在完成后将其添加回来:
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