Simple MouseEnter MouseLeave Events
-
In a C# Windows Forms app, I have a Panel containing some Labels and Pictureboxes. I have set up delegates at the Panel level to handle MouseEnter and MouseLeave Events. I want something to happen when the user moves the mouse into the Panel and out of the Panel. However, the Panel MouseEnter and MouseLeave Events are firing when the mouse moves into and out of any of the Pictureboxes and Labels within the Panel. I don't want this behavior. I want them to fire only when the mouse moves into the Panel and out of the Panel. What am I doing wrong? Thanks, Mark
-
In a C# Windows Forms app, I have a Panel containing some Labels and Pictureboxes. I have set up delegates at the Panel level to handle MouseEnter and MouseLeave Events. I want something to happen when the user moves the mouse into the Panel and out of the Panel. However, the Panel MouseEnter and MouseLeave Events are firing when the mouse moves into and out of any of the Pictureboxes and Labels within the Panel. I don't want this behavior. I want them to fire only when the mouse moves into the Panel and out of the Panel. What am I doing wrong? Thanks, Mark
I'd say you're doing nothing wrong. Because mouse moves above another control it leaves the panel, whether the control is inside or outside the panel. When mouse leaves the panel, you could check the position of the mouse, is it still inside the panel or not. The same logic can be used in MouseEnter. You can get the position from the Cursor class. Hope this helps, Mika
The need to optimize rises from a bad design. My articles[^]