Control.DoubleClick Événement

Définition

Se produit lorsque le contrôle est double-cliqué.

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

Type d'événement

Exemples

L’exemple de code suivant utilise l’événement DoubleClick d’un ListBox pour charger des fichiers texte répertoriés dans un ListBoxTextBox contrôle.

   // 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. L’utilisateur peut définir le temps entre les clics d’un bouton de souris qui doit être considéré comme un double-clic plutôt que deux clics. L’événement Click est déclenché chaque fois qu’un contrôle est double-cliqué. Par exemple, si vous avez des gestionnaires d’événements pour les Click événements d’un FormDoubleClick , les événements et DoubleClick les Click événements sont déclenchés lorsque le formulaire est double-cliqué et les deux méthodes sont appelées. Si un contrôle est double-cliqué et que ce contrôle ne prend pas en charge l’événement DoubleClick , l’événement Click peut être déclenché deux fois.

Vous devez définir les valeurs et les StandardDoubleClickStandardClick valeurs sur ControlStylestrue lesquelles cet événement doit être déclenché. Ces valeurs peuvent déjà être définies sur true si vous héritez des contrôles Windows Forms existants.

Note

Les événements suivants ne sont pas déclenchés pour la TabControl classe, sauf s’il existe au moins un TabPage dans la TabControl.TabPages collection : Click, , DoubleClick, MouseDown, MouseUp, , MouseHover, MouseEnterMouseLeave et MouseMove. S’il y en a au moins un TabPage dans la collection et que l’utilisateur interagit avec l’en-tête du contrôle Tab (où les TabPage noms apparaissent), l’événement TabControl approprié s’affiche. Toutefois, si l’interaction de l’utilisateur se trouve dans la zone cliente de la page d’onglets, l’événement TabPage approprié est déclenche.

Pour plus d'informations sur la gestion des événements, voir gestion et déclenchement d’événements.

Notes pour les héritiers

Hériter d’un contrôle Windows Forms standard et modifier les valeurs StandardClick ou StandardDoubleClick de ControlStyles en true peut provoquer un comportement inattendu ou n’avoir aucun effet du tout si le contrôle ne prend pas en charge les événements Click ou DoubleClick.

Le tableau suivant répertorie les contrôles Windows Forms et quel événement (Click ou DoubleClick) est déclenché en réponse à l’action de la souris spécifiée.

Control Clic gauche de la souris Double-cliquez sur la souris gauche Cliquer avec le bouton droit de la souris Double-cliquez avec la souris droite Clic du milieu de la souris Double-clic de la souris centrale Clic de souris XButton1 XButton1 Mouse Double-Click Clic de souris XButton2 XButton2 Mouse Double-Click
MonthCalendar,

DateTimePicker,

RichTextBox,

HScrollBar,

VScrollBar

Aucune

aucune aucune aucune aucune aucune aucune aucune aucune aucune
Button,

CheckBox,

RadioButton

Cliquez sur

Cliquez, cliquez sur aucune aucune aucune aucune aucune aucune aucune aucune
ListBox,

CheckedListBox,

ComboBox

Cliquez sur

Cliquez sur DoubleClick aucune aucune aucune aucune aucune aucune aucune aucune
TextBox,

DomainUpDown,

NumericUpDown

Cliquez sur

Cliquez sur DoubleClick aucune aucune aucune aucune aucune aucune aucune aucune
* TreeView,

* ListView

Cliquez sur

Cliquez sur DoubleClick Cliquer Cliquez sur DoubleClick aucune aucune aucune aucune aucune aucune
ProgressBar,

TrackBar

Cliquez sur

Cliquez, cliquez sur Cliquer Cliquez, cliquez sur Cliquer Cliquez, cliquez sur Cliquer Cliquez, cliquez sur Cliquer Cliquez, cliquez sur
Form,

DataGrid,

Label,

LinkLabel,

Panel,

GroupBox,

PictureBox,

Splitter,

StatusBar,

ToolBar,

TabPage,

** TabControl

Cliquez sur

Cliquez sur DoubleClick Cliquer Cliquez sur DoubleClick Cliquer Cliquez sur DoubleClick Cliquer Cliquez sur DoubleClick Cliquer Cliquez sur DoubleClick

* Le pointeur de la souris doit se trouver sur un objet enfant (TreeNode ou ListViewItem).

** Le TabControl doit avoir au moins un TabPage dans sa TabPages collection.

S’applique à

Voir aussi