如何在特定情况下抑制MouseMove事件?

时间:2012-03-27 19:48:38

标签: events visual-studio-2005 suppress

我的问题是我需要在MouseMove事件中更改鼠标指针的位置,这会导致无限递归。我需要抑制Me.Cursor.Position = newpos生成的MouseMove事件。我怎么能这样做?

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

1 个答案:

答案 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