Stefan
Stefan

Reputation: 9329

How does Windows decide whether to trigger MouseUp or Click?

I have a control with some complex dragging functionality. It is also clickable.

I'm finding that sometimes a click (rapid mouse down-up, no movement) results in an OnMouseUp event, sometimes a Click event. This appears to be timing dependent...if I put breakpoints on the MouseDown event, I get Click, otherwise I get (mainly) OnMouseUp.

So how does Windows decide which event to trigger?

Thanks

Upvotes: 1

Views: 203

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564423

A mouse click should trigger both events. See Mouse Events in Windows Forms for details, but (from the documentation):

All Windows Forms controls raise click events in the same order when a mouse button is pressed and released (regardless of which mouse button), except where noted in the following list for individual controls. The following list shows the order of events raised for a single mouse-button click:

MouseDown event.

Click event.

MouseClick event.

MouseUp event.

Note that some controls have different behavior (documented in individual controls), and the double click behavior is a bit different, as well (also documented on MSDN).

Also - putting break points in the debugger can cause the message processing behavior to occasionally get a bit strange. I would recommend using Debug.WriteLine or a similar methodology to trace all of the output through the individual messages instead of using breakpoints, if you want to see all of the messages get processed in order.

Upvotes: 2

Related Questions