【问题标题】:How to suppress the MouseMove event in particular case?在特定情况下如何抑制 MouseMove 事件?
【发布时间】:2012-03-27 19:48:37
【问题描述】:
我的问题是我需要在 MouseMove 事件中更改鼠标指针的位置,这会导致无限递归。我需要抑制 Me.Cursor.Position = newpos 生成的 MouseMove 事件。我该怎么做?
我阅读了有关 Me.EnableEvents = False 的信息,但这对 Visual Studio 2005 无效,并且我找不到等效项。
【问题讨论】:
标签:
events
visual-studio-2005
suppress
【解决方案1】:
你到底想做什么?也许有更好的方法。但假设这是您想要的,您可以在使用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