C # mouseleave and mouseenter event will not fire if mouse click

The names say it all. I have a panel that acts like a white board. When moving the mouse, move the mouse over the track .. works fine, but if the mouse leaves the edges of the panel, I want to trigger a mouse event and a mouse event if the mouse leaves or enters the panel, and the button on the left is pressed

private void panel2_MouseLeave(object sender, EventArgs e) { if (mousedraw == true) { panel2_MouseUp(sender, new MouseEventArgs(System.Windows.Forms.MouseButtons.Left, 0, MousePosition.X, MousePosition.Y, 0)); } } private void panel2_MouseEnter(object sender, EventArgs e) { if (mousedraw == true) { panel2_MouseDown(sender, new MouseEventArgs(System.Windows.Forms.MouseButtons.Left, 0, MousePosition.X, MousePosition.Y, 0)); } } 

mousedraw is a bool to find out if the left button is pressed.

Problem :

When you click the mouse, vacation and input events will not fire.

+6
source share
2 answers

MouseEnter and mouseLeave do not fire when a button is clicked. However, when the button is ultimately released, the corresponding mouseEnter or mouseLeave event fires if the mouse moved or exited the panel when the button was pressed. While the button is pressed, the mouseMove event will continue to fire even outside the borders of the panel. This allows the mouse to continue dragging and dropping or something else, even after it goes beyond the control border and how most Windows applications work.

If you can use this behavior in your application, it will be a more “standard” user interface.

If you need to start mouseUp when the mouse leaves the panel, you can check the location of the mouse in the mouseMove event and call mouseUp when it is outside the panel, and the button is pressed. In the MouseMove handler, you can use eX and eY for location and e.Button for button status.

When a mouse is pushed out of control and moved inside, the panel does not have jurisdiction over the mouse because the mouse is considered to be moving in the form or in some other control in which it was clicked. Thus, you may have a problem launching mouseDown when you click the mouse button outside the panel, and then move inside the panel.

+7
source

I don’t think [mousedraw] can succeed

 click = mouseDown + mouseUp 

so

 When mouseDown : mousedraw = false; When mouseUp : mousedraw = true; 
-1
source

Source: https://habr.com/ru/post/896056/


All Articles