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?
Consider the following figure,

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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With