Obtain Position/Button of mouse click on DoubleClick event

user79755 picture user79755 · Mar 27, 2009 · Viewed 15.3k times · Source

Is there a method to obtain the (x, y) coordinates of the mouse cursor in a controls DoubleClick event?

As far as I can tell, the position has to be obtained from the global:

Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y

Also, is there a method to obtain which button produced the double click?

Answer

user410352 picture user410352 · Aug 4, 2010

Use the MouseDoubleClick event rather than the DoubleClick event. MouseDoubleClick provides MouseEventArgs rather than the plain EventArgs. This goes for "MouseClick" rather than "Click" as well...and all the other events that deal with the mouse.

MouseDoubleClick makes sure the mouse is really there. DoubleClick might be caused be something else and the mouse coordinates may not be useful - MSDN: "DoubleClick events are logically higher-level events of a control. They may be raised by other user actions, such as shortcut key combinations."