Control::DoubleClick Event
Occurs when the control is double-clicked.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
A double-click is determined by the mouse settings of the user's operating system. The user can set the time between clicks of a mouse button that should be considered a double-click rather than two clicks. The Click event is raised every time a control is double-clicked. For example, if you have event handlers for the Click and DoubleClick events of a Form, the Click and DoubleClick events are raised when the form is double-clicked and both methods are called. If a control is double-clicked and that control does not support the DoubleClick event, the Click event might be raised twice.
You must set the StandardDoubleClick and StandardClick values of ControlStyles to true for this event to be raised. These values might already be set to true if you are inheriting from existing Windows Forms controls.
Note |
|---|
The following events are not raised for the TabControl class unless there is at least one TabPage in the TabControl::TabPages collection: Click, DoubleClick, MouseDown, MouseUp, MouseHover, MouseEnter, MouseLeave and MouseMove. If there is at least one TabPage in the collection, and the user interacts with the tab control's header (where the TabPage names appear), the TabControl raises the appropriate event. However, if the user interaction is within the client area of the tab page, the TabPage raises the appropriate event. |
For more information about handling events, see Consuming Events.
Notes to InheritorsInheriting from a standard Windows Forms control and changing the StandardClick or StandardDoubleClick values of ControlStyles to true can cause unexpected behavior or have no effect at all if the control does not support the Click or DoubleClick events.
The following table lists Windows Forms controls and which event (Click or DoubleClick) is raised in response to the mouse action specified.
Control | Left Mouse Click | Left Mouse Double Click | Right Mouse Click | Right Mouse Double Click | Middle Mouse Click | Middle Mouse Double Click | XButton1 Mouse Click | XButton1 Mouse Double-Click | XButton2 Mouse Click | XButton2 Mouse Double-Click |
|---|---|---|---|---|---|---|---|---|---|---|
none | none | none | none | none | none | none | none | none | none | |
Click | Click, Click | none | none | none | none | none | none | none | none | |
Click | Click, DoubleClick | none | none | none | none | none | none | none | none | |
Click | Click, DoubleClick | none | none | none | none | none | none | none | none | |
* TreeView, * ListView | Click | Click, DoubleClick | Click | Click, DoubleClick | none | none | none | none | none | none |
Click | Click, Click | Click | Click, Click | Click | Click, Click | Click | Click, Click | Click | Click, Click | |
Form, ** TabControl | Click | Click, DoubleClick | Click | Click, DoubleClick | Click | Click, DoubleClick | Click | Click, DoubleClick | Click | Click, DoubleClick |
* The mouse pointer must be over a child object (TreeNode or ListViewItem).
** The TabControl must have at least one TabPage in its TabPages collection.
The following code example uses the DoubleClick event of a ListBox to load text files listed in the ListBox into a TextBox control.
// This example uses the DoubleClick event of a ListBox to load text files // listed in the ListBox into a TextBox control. This example // assumes that the ListBox, named listBox1, contains a list of valid file // names with path and that this event handler method // is connected to the DoublClick event of a ListBox control named listBox1. // This example requires code access permission to access files. private: void listBox1_DoubleClick( Object^ /*sender*/, System::EventArgs^ /*e*/ ) { // Get the name of the file to open from the ListBox. String^ file = listBox1->SelectedItem->ToString(); try { // Determine if the file exists before loading. if ( System::IO::File::Exists( file ) ) { // Open the file and use a TextReader to read the contents into the TextBox. System::IO::FileInfo^ myFile = gcnew System::IO::FileInfo( listBox1->SelectedItem->ToString() ); System::IO::TextReader^ myData = myFile->OpenText(); ; textBox1->Text = myData->ReadToEnd(); myData->Close(); } } // Exception is thrown by the OpenText method of the FileInfo class. catch ( System::IO::FileNotFoundException^ ) { MessageBox::Show( "The file you specified does not exist." ); } // Exception is thrown by the ReadToEnd method of the TextReader class. catch ( System::IO::IOException^ ) { MessageBox::Show( "There was a problem loading the file into the TextBox. Ensure that the file is a valid text file." ); } }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note