detect mouse leaves control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sam

    detect mouse leaves control

    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(By Val e As System.EventArg s)
    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

  • Ken Tucker [MVP]

    #2
    Re: detect mouse leaves control

    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_MouseEnt er(ByVal sender As Object, ByVal e As
    System.EventArg s) Handles Panel1.MouseEnt er

    Panel1.Capture = True

    End Sub

    Private Sub Panel1_MouseMov e(ByVal sender As Object, ByVal e As
    System.Windows. Forms.MouseEven tArgs) Handles Panel1.MouseMov e

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

    If Not Panel1.ClientRe ctangle.Contain s(pt) Then

    Me.Text = "out of panel"

    Panel1.Capture = False

    Else

    Me.Text = "in panel"

    End If

    End Sub



    Ken

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

    "Sam" <samuel.berthel ot@voila.fr> wrote in message
    news:1119901648 .997544.190000@ g44g2000cwa.goo glegroups.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(By Val e As System.EventArg s)
    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


    Comment

    • Sam

      #3
      Re: detect mouse leaves control

      Thank you so much, it works just fine !
      thank you again :)

      Comment

      Working...