midfield99
midfield99

Reputation: 383

Form ignores some mouse clicks

I'm working on a winforms project where I need to display text and imagery when a mouse click is detected, but I"m running into a few problems. I cannot consistently detect mouse clicks. Here's a basic overview of the program, first the main form loads. Then the user loads another form to set up options. Once that is done, the other form is closed and the main form gets focus. The main form is what should be receiving mouse input. Once a mouse click is detected, a function is called that uses ThreadPool.QueueUserWorkItem to play sound and display imagery.

What happens is that mouse clicks are sometimes ignored in the main form. Usually the first click is ignored, then I'd say more than half of future mouse clicks are ignored. I've added code to notify me when MouseUp fires in the event handler, so I'm certain the event handler is not getting called. I've also set this.Capture = true; in the main form, so I'm not quite sure why some mouse clicks are being ignored. Is there anything that could be interfering with mouse clicks?

Upvotes: 1

Views: 468

Answers (1)

BradleyDotNET
BradleyDotNET

Reputation: 61369

Yes

Plenty of things can interfere with mouse clicks, namely, other UI elements.

If your event handler is on the base container control, and they click in, say, a text box; then the text box receives the click event and the container doesn't.

If your "on top" controls don't need user input, you can simply set IsHitTestVisible (or the WinForms equivalent) to false. If you do need user input, you need to either capture the clicks differently, or add a "MouseUp" event to each control as well.

See Hittest transparency for an entire form and WinForms equivalent of WPF's IsHitTestVisible for ways to do IsHitTestVisible in Winforms. Alternatively, just use WPF.

Upvotes: 1

Related Questions