Files
docs-desktop/dotnet-desktop-guide/framework/winforms/how-to-distinguish-between-clicks-and-double-clicks.md
T
Andy De George c0ba284473 Initial winforms content migrated (#18)
* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
2020-09-01 16:26:21 -07:00

3.9 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Distinguish Between Clicks and Double-Clicks 03/30/2017
csharp
vb
cpp
mouse [Windows Forms], click
mouse [Windows Forms], double-click
mouse clicks [Windows Forms], single versus double
d836ac8c-85bc-4f3a-a761-8aee03dc682c

How to: Distinguish Between Clicks and Double-Clicks

Typically, a single click initiates a user interface (UI) action and a double-click extends the action. For example, one click usually selects an item, and a double-click edits the selected item. However, the Windows Forms click events do not easily accommodate a scenario where a click and a double-click perform incompatible actions, because an action tied to the xref:System.Windows.Forms.Control.Click or xref:System.Windows.Forms.Control.MouseClick event is performed before the action tied to the xref:System.Windows.Forms.Control.DoubleClick or xref:System.Windows.Forms.Control.MouseDoubleClick event. This topic demonstrates two solutions to this problem. One solution is to handle the double-click event and roll back the actions in the handling of the click event. In rare situations you may need to simulate click and double-click behavior by handling the xref:System.Windows.Forms.Control.MouseDown event and by using the xref:System.Windows.Forms.SystemInformation.DoubleClickTime%2A and xref:System.Windows.Forms.SystemInformation.DoubleClickSize%2A properties of the xref:System.Windows.Forms.SystemInformation class. You measure the time between clicks and if a second click occurs before the value of xref:System.Windows.Forms.SystemInformation.DoubleClickTime%2A is reached and the click is within a rectangle defined by xref:System.Windows.Forms.SystemInformation.DoubleClickSize%2A, perform the double-click action; otherwise, perform the click action.

To roll back a click action

To distinguish between clicks in the MouseDown event

Compiling the Code

These examples require:

  • References to the System, System.Drawing, and System.Windows.Forms assemblies.

See also