MouseEnter and MouseLeave events from a Panel and its child controls

后端 未结 9 805
我在风中等你
我在风中等你 2020-12-10 13:14

I have a Panel that contains child controls.

If I handle the Panel\'s MouseEnter and MouseLeave events, and its c

9条回答
  •  自闭症患者
    2020-12-10 13:41

    The mouse is "leaving" the panel as it enters the child control which is why it fires the event.

    You could add something along the following lines in the panel MouseLeave event handler:

    // Check if really leaving the panel
    if (Cursor.Position.X < Location.X ||
        Cursor.Position.Y < Location.Y ||
        Cursor.Position.X > Location.X + Width - 1 ||
        Cursor.Position.Y > Location.Y + Height - 1)
    {
        // Do the panel mouse leave code
    }
    

提交回复
热议问题