467,083 Members | 1,261 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,083 developers. It's quick & easy.

detect mouse leaves control

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

Nov 21 '05 #1
  • viewed: 4427
Share:
2 Replies
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" <sa**************@voila.fr> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.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
Nov 21 '05 #2
Sam
Thank you so much, it works just fine !
thank you again :)

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Qwert | last post: by
4 posts views Thread by cb.brite@gmail.com | last post: by
reply views Thread by Frank Rizzo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.