detect mouse leaves control

  • Thread starter Thread starter Sam
  • Start date Start date
S

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
 
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

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

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
 
Back
Top