Question : mouseleave event on panel, vb.net winforms

I hava a panel on my winforms application.
I have two labels and a link label inside the panel. On mouse leave event on the panel I have code to make the panel.visible = false.

The problem is even when I hoover inside the panel on the label or link label this code is executed and the panel closes. How can I make sure this code gets executed only when the mouse is outside the panel and not executed when the mouse is over any control inside the panel. Please help. Thanks

Answer : mouseleave event on panel, vb.net winforms

You can do something like this:
1:
2:
3:
4:
5:
6:
7:
8:
9:
    Private Sub Panel1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Panel1.MouseLeave
        Dim pnl As Panel = CType(sender, Panel)
        Dim rc As Rectangle = pnl.RectangleToScreen(pnl.ClientRectangle)
        If Not rc.Contains(Cursor.Position) Then
            pnl.Visible = False
        Else
            Debug.Print("MouseLeave() but cursor still within panel bounds")
        End If
    End Sub
Random Solutions  
 
programming4us programming4us