This is an annoyance I am seeing with .NET WinForms mouse events. To reproduce, do the following:
- Left mouse down on a Button Control. (This changes the capture control to that button)
- Move mouse off of that button.
- While still holding on to the left mouse button, click the right mouse button. (This changes the capture control to whatever the mouse cursor is over now)
- Release the left mouse button. The button never receives the mouse up event. (The mouse up event goes to the current capture control.)
I only care about the left mouse button, but a user accidentally pressing the right button prevents the left-mouse-up event from getting back to the originally clicked button.
One possible solution is to use the MouseLeave or MouseCaptureChanged events to detect when the right click is happening off of the button and know when the capture control has changed. I have tried this, and it works pretty well.
Another way is to use MessageFilters and filter out right button events. But some buttons needs the right clicks, so you don't want to filter out ALL right clicks, just for buttons that need this feature.
So I am asking to see if anyone knows of a better solution. It would be nice if windows had some kind of flag to do the following:
button1.RightMouseButtonCanChangeMouseCapture = false;