1

我试图使用 MouseLeave 事件来隐藏包含 TreeView 对象的 Popup 控件。很快就发现了第一个细微差别,即 Popup 控件不会发出 MouseLeave 事件。因此,我采用了规定的 hackaround 并从 Child 对象中捕获了事件。然后我遇到了第二个细微差别。鼠标进入控件后立即触发 MouseLeave 事件。我发现 TreeView 控件在进入 TreeView 对象时会发出一系列交替的 MouseEnter 和 MouseLeave 事件。

以下代码使用 IE8 生成了这一点的证据:

Public Class MainApp
    Inherits Application

    Dim _cnt As Integer = 1

    Public Sub New()
        AddHandler Me.Startup, AddressOf HandleStartup
    End Sub

    Private Sub HandleStartup()
        Dim tv As New TreeView
        AddHandler tv.MouseEnter, AddressOf HandleMouseEnter
        AddHandler tv.MouseLeave, AddressOf HandleMouseLeave
        RootVisual = tv
    End Sub
    Private Sub HandleMouseEnter(ByVal sender As Object, ByVal ev As MouseEventArgs)
        System.Diagnostics.Debugger.Log(0, Nothing, "MouseEnter " & _cnt & vbCrLf)
        _cnt += 1
    End Sub
    Private Sub HandleMouseLeave(ByVal sender As Object, ByVal ev As MouseEventArgs)
        System.Diagnostics.Debugger.Log(0, Nothing, "MouseLeave " & _cnt & vbCrLf)
        _cnt += 1
    End Sub

End Class

我希望看到的地方

MouseEnter 1
...
MouseLeave 2

相反,我看到

MouseEnter 1
MouseLeave 2
MouseEnter 3
...
MouseLeave 4

所以在 MouseLeave 上隐藏控件是一场失败的战斗。关于正在发生的事情或可以做些什么来解决它的任何想法?

4

0 回答 0