Home All Groups Group Topic Archive Search About

detect mouse leaves control

Author
27 Jun 2005 7:47 PM
Sam
Hi,
I can't figure out how to detect when my mouse cursor leaves a panel
control. It should not trigger the event (or do anything) when the
mouse leave the panel but still is over a control that is contained by
the panel.
I've done this :

Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
    If Cursor.Position.X > Me.Location.X + Me.Width Or
Cursor.Position.Y > Me.Location.Y + Me.Height _
    Or Cursor.Position.X < Me.Location.X Or Cursor.Position.Y <
Me.Location.Y Then
            MsgBox("Out")
     End If
End Sub

That doesn't work well. what is the correct method ?

Thx

Author
27 Jun 2005 9:19 PM
Ken Tucker [MVP]
Hi,

                Capture the mouse when it enters the panel.  Check and see
if the mouse is inside the panel when it moves.  Release it when it exits.

Private Sub Panel1_MouseEnter(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Panel1.MouseEnter

Panel1.Capture = True

End Sub

Private Sub Panel1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove

Dim pt As New Point(e.X, e.Y)

If Not Panel1.ClientRectangle.Contains(pt) Then

Me.Text = "out of panel"

Panel1.Capture = False

Else

Me.Text = "in panel"

End If

End Sub



Ken

---------------------------------

"Sam" <samuel.berthe***@voila.fr> wrote in message
news:1119901648.997544.190000@g44g2000cwa.googlegroups.com...
Hi,
I can't figure out how to detect when my mouse cursor leaves a panel
control. It should not trigger the event (or do anything) when the
mouse leave the panel but still is over a control that is contained by
the panel.
I've done this :

Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
    If Cursor.Position.X > Me.Location.X + Me.Width Or
Cursor.Position.Y > Me.Location.Y + Me.Height _
    Or Cursor.Position.X < Me.Location.X Or Cursor.Position.Y <
Me.Location.Y Then
            MsgBox("Out")
     End If
End Sub

That doesn't work well. what is the correct method ?

Thx
Author
27 Jun 2005 9:30 PM
Sam
Thank you so much, it works just fine !
thank you again :)