Control.DoubleClick Événement

Définition

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

public:
 event EventHandler ^ DoubleClick;
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 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. 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 et DoubleClick d’un Form, les Click événements et DoubleClick sont déclenchés lorsque le formulaire est double-cliqué et que 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 StandardDoubleClick valeurs et StandardClick de ControlStyles sur true pour que cet événement soit déclenché. Ces valeurs peuvent déjà être définies sur true si vous héritez de contrôles Windows Forms existants.

Notes

Les événements suivants ne sont pas déclenchés pour la TabControl classe, sauf s’il en existe au moins un TabPage dans la TabControl.TabPages collection : Click, DoubleClick, MouseDown, MouseUp, MouseHover, MouseEnteret MouseLeaveMouseMove. 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 d’onglet (où les TabPage noms apparaissent), le TabControl déclenche l’événement approprié. Toutefois, si l’interaction de l’utilisateur se trouve dans la zone cliente de la page d’onglet, le TabPage déclenche l’événement approprié.

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

Notes pour les héritiers

L’héritage d’un contrôle Windows Forms standard et la StandardClick modification des valeurs ou StandardDoubleClick de ControlStyles à peuvent true entraîner un comportement inattendu ou n’avoir aucun effet du tout si le contrôle ne prend pas en charge les Click événements ou DoubleClick .

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

Control Clic gauche de la souris Double-clic gauche de la souris Clic droit de la souris Double-clic de la souris avec le bouton droit Clic au milieu de la souris Double-clic de la souris centrale XButton1 Clic de souris Double-Click souris XButton1 XButton2 Clic de souris Double-Click de souris XButton2
MonthCalendar,

DateTimePicker,

RichTextBox,

HScrollBar,

VScrollBar

aucun aucun aucun aucun aucun aucun aucun aucun aucun aucun
Button,

CheckBox,

RadioButton

Cliquez Cliquez, cliquez sur aucun aucun aucun aucun aucun aucun aucun aucun
ListBox,

CheckedListBox,

ComboBox

Cliquez Cliquez sur, DoubleClick aucun aucun aucun aucun aucun aucun aucun aucun
TextBox,

DomainUpDown,

NumericUpDown

Cliquez Cliquez sur, DoubleClick aucun aucun aucun aucun aucun aucun aucun aucun
* TreeView,

* ListView

Cliquez Cliquez sur, DoubleClick Cliquez Cliquez sur, DoubleClick aucun aucun aucun aucun aucun aucun
ProgressBar,

TrackBar

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

DataGrid,

Label,

LinkLabel,

Panel,

GroupBox,

PictureBox,

Splitter,

StatusBar,

ToolBar,

TabPage,

** TabControl

Cliquez Cliquez sur, DoubleClick Cliquez Cliquez sur, DoubleClick Cliquez Cliquez sur, DoubleClick Cliquez Cliquez sur, DoubleClick Cliquez Cliquez sur, DoubleClick

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

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

S’applique à

Voir aussi