Control.DoubleClick Control.DoubleClick Control.DoubleClick Control.DoubleClick Event

Définition

Se produit à la suite d'un double-clic sur le contrôle.Occurs when the control is double-clicked.

public:
 event EventHandler ^ DoubleClick;
public event EventHandler DoubleClick;
member this.DoubleClick : EventHandler 
Public Custom Event DoubleClick As EventHandler 

Exemples

L’exemple de code suivant utilise DoubleClick l’événement d' ListBox un pour charger des fichiers texte figurant ListBox dans le TextBox dans un contrôle.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." );
      }
   }
// 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.");
    }
}
' 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 Sub listBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles listBox1.DoubleClick
    ' Get the name of the file to open from the ListBox.
    Dim file As [String] = listBox1.SelectedItem.ToString()

    Try
        ' Determine if the file exists before loading.
        If System.IO.File.Exists(file) Then
            ' Open the file and use a TextReader to read the contents into the TextBox.
            Dim myFile As New System.IO.FileInfo(listBox1.SelectedItem.ToString())
            Dim myData As System.IO.TextReader = myFile.OpenText()

            textBox1.Text = myData.ReadToEnd()
            myData.Close()
        End If
        ' Exception is thrown by the OpenText method of the FileInfo class.
    Catch
        MessageBox.Show("The file you specified does not exist.")
        ' Exception is thrown by the ReadToEnd method of the TextReader class.
    Catch
     MessageBox.Show("There was a problem loading the file into the TextBox. Ensure that the file is a valid text file.")
    End Try
End Sub

Remarques

Un double-clic est déterminé par les paramètres de la souris du système d’exploitation de l’utilisateur.A double-click is determined by the mouse settings of the user's operating system. L'utilisateur peut définir le délai qui détermine si les clics effectués sur un bouton de souris sont considérés comme un double-clic ou comme deux clics.The user can set the time between clicks of a mouse button that should be considered a double-click rather than two clicks. L' Click événement est déclenché chaque fois que l’utilisateur double-clique sur un contrôle.The Click event is raised every time a control is double-clicked. Par exemple, si vous avez des gestionnaires d’événements pour Click les DoubleClick événements et d' Formun, Click les DoubleClick événements et sont déclenchés lorsque l’utilisateur double-clique sur le formulaire et que les deux méthodes sont appelées.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. Si vous double-cliquez sur un contrôle et que ce contrôle ne prend pas DoubleClick en charge l' Click événement, l’événement peut être déclenché deux fois.If a control is double-clicked and that control does not support the DoubleClick event, the Click event might be raised twice.

Vous devez définir les StandardDoubleClick valeurs StandardClick et de ControlStyles à true pour que cet événement soit déclenché.You must set the StandardDoubleClick and StandardClick values of ControlStyles to true for this event to be raised. Ces valeurs peuvent déjà avoir la valeur true si vous héritez de contrôles de Windows Forms existants.These values might already be set to true if you are inheriting from existing Windows Forms controls.

Notes

Les événements suivants ne sont pas déclenchés TabControl pour la classe, sauf s’il TabPage y en a au moins un MouseDowndans MouseUpla MouseHover TabControl.TabPages collection MouseEnter: Click, DoubleClick,,,,, MouseLeave et .MouseMoveThe 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. Si la collection contient au moins TabPage un, et que l’utilisateur interagit avec l’en-tête du contrôle onglet (où TabPage les noms apparaissent), TabControl le déclenche l’événement approprié.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. Toutefois, si l’interaction de l’utilisateur se trouve dans la zone cliente de la TabPage page d’onglets, le déclenche l’événement approprié.However, if the user interaction is within the client area of the tab page, the TabPage raises the appropriate event.

Pour plus d'informations sur la gestion des événements, voir gestion et déclenchement d’événements.For more information about handling events, see Handling and Raising Events.

Notes pour les héritiers

L’héritage d’un contrôle Windows Forms StandardClick standard et la modification des valeurs ou ControlStyles StandardDoubleClick de true en peuvent entraîner un Click comportement inattendu ou n’avoir aucun effet si le contrôle ne prend pas en charge ou DoubleClick.événements.Inheriting 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.

Le tableau suivant répertorie Windows Forms contrôles et l’événementClick ( DoubleClickou) qui est déclenché en réponse à l’action de la souris spécifiée.The following table lists Windows Forms controls and which event (Click or DoubleClick) is raised in response to the mouse action specified.

ContrôleControl Cliquer avec le bouton gauche de la sourisLeft Mouse Click Double-clic de la souris gaucheLeft Mouse Double Click Clic droit de la sourisRight Mouse Click Double-clic de droite de la sourisRight Mouse Double Click Clic de souris du milieuMiddle Mouse Click Double-clic de la souris du milieuMiddle Mouse Double Click Le bouton XButton1 clic de sourisXButton1 Mouse Click Double-clic de la souris le bouton XButton1XButton1 Mouse Double-Click XButton2 clic de sourisXButton2 Mouse Click Double-clic de la souris XButton2XButton2 Mouse Double-Click
MonthCalendar,MonthCalendar, DateTimePicker,DateTimePicker, RichTextBox,RichTextBox, HScrollBar,HScrollBar, VScrollBar nonenone nonenone nonenone nonenone nonenone nonenone nonenone nonenone nonenone nonenone
Button,Button, CheckBox,CheckBox, RadioButton ClicClick Cliquez sur, surClick, Click nonenone nonenone nonenone nonenone nonenone nonenone nonenone nonenone
ListBox,ListBox, CheckedListBox,CheckedListBox, ComboBox ClicClick Click, DoubleClickClick, DoubleClick nonenone nonenone nonenone nonenone nonenone nonenone nonenone nonenone
TextBox,TextBox, DomainUpDown,DomainUpDown, NumericUpDown ClicClick Click, DoubleClickClick, DoubleClick nonenone nonenone nonenone nonenone nonenone nonenone nonenone nonenone
\* TreeView,\* TreeView, \* ListView\* ListView ClicClick Click, DoubleClickClick, DoubleClick ClicClick Click, DoubleClickClick, DoubleClick nonenone nonenone nonenone nonenone nonenone nonenone
ProgressBar,ProgressBar, TrackBar ClicClick Cliquez sur, surClick, Click ClicClick Cliquez sur, surClick, Click ClicClick Cliquez sur, surClick, Click ClicClick Cliquez sur, surClick, Click ClicClick Cliquez sur, surClick, Click
Form,Form, DataGrid,DataGrid, Label,Label, LinkLabel,LinkLabel, Panel,Panel, GroupBox,GroupBox, PictureBox,PictureBox, Splitter,Splitter, StatusBar,StatusBar, ToolBar,ToolBar, TabPage,TabPage, ** TabControl ClicClick Click, DoubleClickClick, DoubleClick ClicClick Click, DoubleClickClick, DoubleClick ClicClick Click, DoubleClickClick, DoubleClick ClicClick Click, DoubleClickClick, DoubleClick ClicClick Click, DoubleClickClick, DoubleClick

*Le pointeur de la souris doit être sur un objetTreeNode enfant ListViewItem(ou).* The mouse pointer must be over a child object (TreeNode or ListViewItem).

* * Le TabControl doit avoir au moins un TabPage dans sa TabPages collection.** The TabControl must have at least one TabPage in its TabPages collection.

S’applique à

Voir aussi