I have what would seem to be a simple problem, but I can't get it. To save screen space, I'm trying to create a simple autohide window using a panel control, which will slide open and closed on the MouseEnter and MouseLeave events. For example, here's what I have on MouseEnter. With the opposite on MouseLeave.

If NavPnl1.Height = 500 Then
        Else
            NavPnl1.BorderStyle = BorderStyle.Fixed3D
            For i As Integer = 1 To 500
                NavPnl1.Height = i
            Next
        End If

This works fine, but the only problem is that the MouseLeave is fired when I cross another control on the same panel...closing the panel down (and making it worthless). Does anyone have a quick solution to keep the MouseLeave event on the panel from firing when another control is crossed? Or another way to accomplish the same?

Thanks in advance!

Recommended Answers

All 4 Replies

Hi Marshall

IMO, Change the location of the panel instead of height, Keep the height constant.

Dim A As New Size(Me.Size)
        Panel1.Location = New Point(A.Width, A.Height - 500)
' Control the variable A with main for resize event
' Open Up
        For i = 1 To 500
            Panel1.Location = New Point(A.Width, A.Height - 500 + i)
        Next
' Wind up
        For i = 500 To 1 Step -1
           Panel1.Location = New Point(A.Width, A.Height - 500 + i)
        Next

Using Timer Control is the best option no matters where the focus goes it works perfectly.

Rgrds

Sam

to keep the MouseLeave event on the panel from firing when another control is crossed? Or another way to accomplish the same?

You can't prevent that event. But instead of mouse leaving the panel, you should think where the mouse enters. I would assume that the mouse enters a form. So you "hide" the panel if
1) mouse enters the form and
2) before that mouse was on the panel
Something like this

Private leftFromPanel As Boolean = False

Private Sub Form1_MouseEnter(sender As Object, e As System.EventArgs) Handles Me.MouseEnter

    If leftFromPanel Then
        Panel1.BorderStyle = BorderStyle.None
        For i As Integer = 500 To 10 Step -1 ' Leave 10 px "handle" to open the panel
            Panel1.Height = i
        Next i
        leftFromPanel = False
    End If

End Sub

Private Sub Panel1_MouseLeave(sender As Object, e As System.EventArgs) Handles Panel1.MouseLeave

    leftFromPanel = True

End Sub

If the panel is over some other control, like SplitContainer, you trap SplitContainer's MouseEnter instead of form's.

HTH

Member Avatar for Unhnd_Exception
'Check if the panel still contains the cursor on leave.
    Private Sub Panel1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Panel1.MouseLeave
        If Panel1.ClientRectangle.Contains(Panel1.PointToClient(Cursor.Position)) Then
            'The mouse left the panel but it is still inside the panel
            'ie a child control.  Do nothing or something
        Else
            'Mouse completley left the panel
            Panel1.Visible = False
        End If
    End Sub

Thanks All. Both Teme and Unhnd provided workable solutions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.