Cet article a fait l’objet d’une traduction automatique. Pour afficher l’article en anglais, activez la case d’option Anglais. Vous pouvez également afficher le texte anglais dans une fenêtre contextuelle en faisant glisser le pointeur de la souris sur le texte traduit.
Traduction
Anglais

Control.DoubleClick événement

 

Date de publication : novembre 2016

Se produit à la suite d'un double-clic sur le contrôle.

Espace de noms:   System.Windows.Forms
Assembly:  System.Windows.Forms (dans System.Windows.Forms.dll)

public event EventHandler DoubleClick

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 E:System.Windows.Forms.Control.Click event is raised every time a control is double-clicked. For example, if you have event handlers for the E:System.Windows.Forms.Control.Click and E:System.Windows.Forms.Control.DoubleClick events of a T:System.Windows.Forms.Form, the E:System.Windows.Forms.Control.Click and E:System.Windows.Forms.Control.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 E:System.Windows.Forms.Control.DoubleClick event, the E:System.Windows.Forms.Control.Click event might be raised twice.

You must set the StandardDoubleClick and StandardClick values of T:System.Windows.Forms.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.

System_CAPS_noteRemarque

The following events are not raised for the T:System.Windows.Forms.TabControl class unless there is at least one T:System.Windows.Forms.TabPage in the P:System.Windows.Forms.TabControl.TabPages collection: E:System.Windows.Forms.Control.Click, E:System.Windows.Forms.Control.DoubleClick, E:System.Windows.Forms.Control.MouseDown, E:System.Windows.Forms.Control.MouseUp, E:System.Windows.Forms.Control.MouseHover, E:System.Windows.Forms.Control.MouseEnter, E:System.Windows.Forms.Control.MouseLeave and E:System.Windows.Forms.Control.MouseMove. If there is at least one T:System.Windows.Forms.TabPage in the collection, and the user interacts with the tab control's header (where the T:System.Windows.Forms.TabPage names appear), the T:System.Windows.Forms.TabControl raises the appropriate event. However, if the user interaction is within the client area of the tab page, the T:System.Windows.Forms.TabPage raises the appropriate event.

For more information about handling events, see Handling and Raising Events.

Remarques à l’attention des héritiers :

Inheriting from a standard Windows Forms control and changing the StandardClick or StandardDoubleClick values of T:System.Windows.Forms.ControlStyles to true can cause unexpected behavior or have no effect at all if the control does not support the E:System.Windows.Forms.Control.Click or E:System.Windows.Forms.Control.DoubleClick events.

The following table lists Windows Forms controls and which event (E:System.Windows.Forms.Control.Click or E:System.Windows.Forms.Control.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

MonthCalendar,

DateTimePicker,

RichTextBox,

HScrollBar,

VScrollBar

none

none

none

none

none

none

none

none

none

none

Button,

CheckBox,

RadioButton

Click

Click, Click

none

none

none

none

none

none

none

none

ListBox,

CheckedListBox,

ComboBox

Click

Click, DoubleClick

none

none

none

none

none

none

none

none

TextBox,

DomainUpDown,

NumericUpDown

Click

Click, DoubleClick

none

none

none

none

none

none

none

none

* T:System.Windows.Forms.TreeView,

* T:System.Windows.Forms.ListView

Click

Click, DoubleClick

Click

Click, DoubleClick

none

none

none

none

none

none

ProgressBar,

TrackBar

Click

Click, Click

Click

Click, Click

Click

Click, Click

Click

Click, Click

Click

Click, Click

Form,

DataGrid,

Label,

LinkLabel,

Panel,

GroupBox,

PictureBox,

Splitter,

StatusBar,

ToolBar,

TabPage,

** T:System.Windows.Forms.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 (T:System.Windows.Forms.TreeNode or T:System.Windows.Forms.ListViewItem).

** The T:System.Windows.Forms.TabControl must have at least one T:System.Windows.Forms.TabPage in its P:System.Windows.Forms.TabControl.TabPages collection.

The following code example uses the E:System.Windows.Forms.Control.DoubleClick event of a T:System.Windows.Forms.ListBox to load text files listed in the T:System.Windows.Forms.ListBox into a T:System.Windows.Forms.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 = new 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.");
    }
}

.NET Framework
Disponible depuis 1.1
Retour au début
Afficher: