3

I have 2 panels (Panel1 and Panel2) with Panel2 placed inside of Panel1

My code:

Private Sub Panel1_MouseLeave(sender As Object, e As EventArgs) Handles Panel1.MouseLeave
    MsgBox("Leave")
End Sub

The MsgBox pops-up when my mouse goes inside Panel2.

This is not logical, because my mouse is still contained in the area of ​​Panel1.

How can Panel2 be considered the same area as Panel1 for event purposes?

Jesus Ramos
  • 22,940
  • 10
  • 58
  • 88
  • or this one for that matter http://stackoverflow.com/questions/1161280/parent-control-mouse-enter-leave-events-with-child-controls although, the code in an answer kinda' lacks the working part. – Gman Mar 12 '13 at 19:25

1 Answers1

2

Consider the following figure,

enter image description here

Assume that the above picture is representing a two concrete slabs(Two panels) placed one above another (light gray:panel1, dark gray: panel2).

You are the person(Cursor) asked to stand up on position 1 in light-gray slab, what you will do, First you will enter into the light gray slab.[panel1.mouseEnter event got fired ] and finally you will reach the positon 1. similarly again you asked to stand up on the position 2 in dark gray slab, what you will do this time, you will leave the light gray slab [panel1.mouseLeave event got fired] and then you will enter into the dark gray slab [panel2.mouseEnter event got fired]. Did you notice.? you had left the light gray slab in order to enter into the dark gray one.

Similarly, Inside a form, especially on a stack of controls, One Control's Mouse Enter should be the previous control's Mouse Leave.

Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130
  • Not exactly true. You can (very fast, programmatically, using pen hovering above the screen with pen input) move the mouse *right into* the position two, so there won't be any events for the `panel1` at all. – Gman Mar 12 '13 at 19:40
  • 1
    @Gman you are right, it is a known issue.But OP's requirement is to know, `why Panel1's leave event called, still mouse is inside of it`. and by the way i thought that he needed a logical answer. :) – Rajaprabhu Aravindasamy Mar 12 '13 at 20:20