Control.DoubleClick Ereignis

Definition

Tritt beim Doppelklicken auf das Steuerelement ein.

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

Ereignistyp

Beispiele

Im folgenden Codebeispiel wird das DoubleClick -Ereignis eines ListBox verwendet, um textdateien, die in der ListBox aufgelistet sind, in ein -Steuerelement zu TextBox laden.

   // 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

Hinweise

Ein Doppelklick wird durch die Mauseinstellungen des Betriebssystems des Benutzers bestimmt. Der Benutzer kann den Zeitraum festlegen, innerhalb dessen der zweite Mausklick erfolgen muss, damit zwei aufeinander folgende Mausklicks als Doppelklick erkannt werden. Das Click Ereignis wird jedes Mal ausgelöst, wenn auf ein Steuerelement doppelklicken wird. Wenn Sie z. B. Über Ereignishandler für die Click Ereignisse und DoubleClick eines Formverfügen, werden die Click Ereignisse und DoubleClick ausgelöst, wenn auf das Formular doppelklicken und beide Methoden aufgerufen werden. Wenn auf ein Steuerelement doppelklicken wird und dieses Steuerelement das DoubleClick Ereignis nicht unterstützt, wird das Click Ereignis möglicherweise zweimal ausgelöst.

Sie müssen die StandardDoubleClick Werte und StandardClick von ControlStyles auf festlegen, true damit dieses Ereignis ausgelöst wird. Diese Werte sind möglicherweise bereits auf true festgelegt, wenn Sie von vorhandenen Windows Forms-Steuerelementen erben.

Hinweis

Die folgenden Ereignisse werden für die TabControl -Klasse nur ausgelöst, wenn mindestens eins TabPage in der TabControl.TabPages Auflistung vorhanden ist: Click, DoubleClick, MouseDown, MouseUpMouseHover, MouseEnter, MouseLeave und MouseMove. Wenn mindestens eine TabPage in der Auflistung vorhanden ist und der Benutzer mit der Kopfzeile des Registerkartensteuerelements interagiert (wo die TabPage Namen angezeigt werden), löst das TabControl entsprechende Ereignis aus. Wenn sich die Benutzerinteraktion jedoch im Clientbereich der Registerkartenseite befindet, löst das TabPage entsprechende Ereignis aus.

Weitere Informationen zur Behandlung von Ereignissen finden Sie unter behandeln und Auslösen von Ereignissen.

Hinweise für Vererber

Das Erben von einem Standard-Windows Forms Steuerelements und das Ändern der StandardClick Werte oder StandardDoubleClick von ControlStyles in true kann zu unerwartetem Verhalten führen oder überhaupt keine Auswirkungen haben, wenn das Steuerelement die Click - oder DoubleClick -Ereignisse nicht unterstützt.

In der folgenden Tabelle sind Windows Forms Steuerelemente aufgeführt und welches Ereignis (Click oder DoubleClick) als Reaktion auf die angegebene Mausaktion ausgelöst wird.

Control Linker Mausklick Doppelklick mit der linken Maustaste Rechtsklick Doppelklick mit der rechten Maustaste Mittlerer Mausklick Mittlerer Maus-Doppelklick XButton1-Mausklick XButton1-Maus-Double-Click XButton2-Mausklick XButton2-Maus-Double-Click
MonthCalendar,

DateTimePicker,

RichTextBox,

HScrollBar,

VScrollBar

Keine Keine Keine Keine Keine Keine Keine Keine Keine Keine
Button,

CheckBox,

RadioButton

Klicken Sie auf Klicken, Klicken Keine Keine Keine Keine Keine Keine Keine Keine
ListBox,

CheckedListBox,

ComboBox

Klicken Sie auf Klicken Sie, DoubleClick Keine Keine Keine Keine Keine Keine Keine Keine
TextBox,

DomainUpDown,

NumericUpDown

Klicken Sie auf Klicken Sie, DoubleClick Keine Keine Keine Keine Keine Keine Keine Keine
* TreeView,

* ListView

Klicken Sie auf Klicken Sie, DoubleClick Klicken Sie auf Klicken Sie, DoubleClick Keine Keine Keine Keine Keine Keine
ProgressBar,

TrackBar

Klicken Sie auf Klicken, Klicken Klicken Sie auf Klicken, Klicken Klicken Sie auf Klicken, Klicken Klicken Sie auf Klicken, Klicken Klicken Sie auf Klicken, Klicken
Form,

DataGrid,

Label,

LinkLabel,

Panel,

GroupBox,

PictureBox,

Splitter,

StatusBar,

ToolBar,

TabPage,

** TabControl

Klicken Sie auf Klicken Sie, DoubleClick Klicken Sie auf Klicken Sie, DoubleClick Klicken Sie auf Klicken Sie, DoubleClick Klicken Sie auf Klicken Sie, DoubleClick Klicken Sie auf Klicken Sie, DoubleClick

* Der Mauszeiger muss sich über einem untergeordneten Objekt (TreeNode oder ListViewItem) bewegen.

** Die TabControl muss mindestens einen TabPage in seiner TabPages Sammlung enthalten.

Gilt für:

Weitere Informationen