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

Le code suivant exemple utilise le DoubleClick événement d’un ListBox pour charger des fichiers texte répertoriés dans le ListBox dans un TextBox 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. Le Click événement est déclenché chaque fois qu’un double-clic est effectué 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 le Click et DoubleClick événements d’un Form, le Click et DoubleClick sont déclenchés lorsqu’un double-clic est effectué sur le formulaire et 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 un contrôle utilisateur double-clique sur et que contrôle ne prend pas en charge la DoubleClick événement, le Click 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 le StandardDoubleClick et StandardClick les valeurs de ControlStyles à true pour cet événement à déclencher.You must set the StandardDoubleClick and StandardClick values of ControlStyles to true for this event to be raised. Ces valeurs peuvent déjà être définies pour true si vous héritez existant des contrôles Windows Forms.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 pour la TabControl classe sauf s’il existe au moins un TabPage dans le TabControl.TabPages collection : Click, DoubleClick, MouseDown, MouseUp, MouseHover, MouseEnter, MouseLeave et MouseMove.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. S’il existe au moins un TabPage dans la collection, et l’utilisateur interagit avec l’onglet en-tête du contrôle (où le TabPage noms apparaissent), le TabControl 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 utilisateur se trouve dans la zone cliente de la page d’onglets, le TabPage 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

Héritage d’un contrôle Windows Forms standard et en modifiant le StandardClick ou StandardDoubleClick les valeurs de ControlStyles à true peut provoquer un comportement inattendu ou carrément n’ont aucun effet si le contrôle ne prend pas en charge la Click 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 les contrôles Windows Forms et les événements (Click ou DoubleClick) 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 Clic gaucheLeft Mouse Click Double clic gaucheLeft Mouse Double Click Cliquez sur le droit de la sourisRight Mouse Click Droit de la souris, double-cliquez surRight Mouse Double Click Cliquez sur le milieu de la sourisMiddle Mouse Click Central de la souris, double-cliquez surMiddle Mouse Double Click Clic de souris XButton1XButton1 Mouse Click XButton1 de la sourisXButton1 Mouse Double-Click Clic de souris XButton2XButton2 Mouse Click XButton2 de la sourisXButton2 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, cliquez 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, cliquez surClick, Click ClicClick Cliquez sur, cliquez surClick, Click ClicClick Cliquez sur, cliquez surClick, Click ClicClick Cliquez sur, cliquez surClick, Click ClicClick Cliquez sur, cliquez 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 objet enfant (TreeNode ou ListViewItem).* The mouse pointer must be over a child object (TreeNode or ListViewItem).

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

S’applique à

Voir aussi