Control.DoubleClick Zdarzenie

Definicja

Występuje po dwukrotnym kliknięciu kontrolki.

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

Typ zdarzenia

Przykłady

Poniższy przykład kodu używa DoubleClick zdarzenia , ListBox aby załadować pliki tekstowe wymienione w ListBox kontrolce TextBox .

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

Uwagi

Dwukrotnie kliknięcie konfiguruje się w ustawieniach myszy w systemie operacyjnym użytkownika. Użytkownik może ustawić czas między kliknięciami przycisku myszy, które należy uznać za dwukrotne kliknięcie, a nie dwa kliknięcia. Zdarzenie Click jest wywoływane za każdym razem, gdy kontrolka jest dwukrotnie klikana. Jeśli na przykład masz programy obsługi zdarzeń dla Click zdarzeń i DoubleClick , zdarzenia Click i DoubleClick są wywoływane, gdy formularz jest dwukrotnie klikany, a obie metody są wywoływaneForm. Jeśli kontrolka jest dwukrotnie kliknięta i ta kontrolka nie obsługuje DoubleClick zdarzenia, Click zdarzenie może zostać zgłoszone dwukrotnie.

Należy ustawić StandardDoubleClick wartości i StandardClick dla ControlStylestrue tego zdarzenia, które mają zostać podniesione. Te wartości mogą być już ustawione, true jeśli dziedziczysz z istniejących kontrolek Windows Forms.

Uwaga

Następujące zdarzenia nie są wywoływane dla TabControl klasy, chyba że istnieje co najmniej jeden TabPage w TabControl.TabPages kolekcji: Click, , , MouseUpMouseHoverMouseDownMouseEnterDoubleClickMouseLeave i .MouseMove Jeśli w kolekcji znajduje się co najmniej jeden TabPage element, a użytkownik wchodzi w interakcję z nagłówkiem kontrolki karty (gdzie TabPage są wyświetlane nazwy), TabControl zgłasza odpowiednie zdarzenie. Jeśli jednak interakcja użytkownika znajduje się w obszarze klienta na stronie karty, TabPage program zgłasza odpowiednie zdarzenie.

Aby uzyskać więcej informacji na temat obsługi zdarzeń, zobacz Obsługa i podnoszenie zdarzeń.

Uwagi dotyczące dziedziczenia

Dziedziczenie ze standardowej kontrolki Windows Forms i zmiana StandardClick wartości ControlStyles lub StandardDoubleClick do może spowodować true nieoczekiwane zachowanie lub nie ma żadnego wpływu, jeśli kontrolka nie obsługuje Click zdarzeń lub DoubleClick .

W poniższej tabeli wymieniono kontrolki Windows Forms i które zdarzenie (Click lub DoubleClick) jest zgłaszane w odpowiedzi na akcję myszy określoną.

Kontrola Kliknięcie lewym przyciskiem myszy Dwukrotne kliknięcie lewym przyciskiem myszy Kliknięcie prawym przyciskiem myszy Dwukrotne kliknięcie prawym przyciskiem myszy Kliknięcie myszą środkową Kliknij dwukrotnie środkową mysz XButton1 Kliknij myszą Double-Click myszy XButton1 XButton2 Kliknij myszą Double-Click myszy XButton2
MonthCalendar,

DateTimePicker,

RichTextBox,

HScrollBar,

VScrollBar

brak brak brak brak brak brak brak brak brak brak
Button,

CheckBox,

RadioButton

Kliknij Kliknij, kliknij brak brak brak brak brak brak brak brak
ListBox,

CheckedListBox,

ComboBox

Kliknij Kliknij, Kliknij dwukrotnieKliknij brak brak brak brak brak brak brak brak
TextBox,

DomainUpDown,

NumericUpDown

Kliknij Kliknij, Kliknij dwukrotnieKliknij brak brak brak brak brak brak brak brak
* TreeView,

* ListView

Kliknij Kliknij, Kliknij dwukrotnieKliknij Kliknij Kliknij, Kliknij dwukrotnieKliknij brak brak brak brak brak brak
ProgressBar,

TrackBar

Kliknij Kliknij, kliknij Kliknij Kliknij, kliknij Kliknij Kliknij, kliknij Kliknij Kliknij, kliknij Kliknij Kliknij, kliknij
Form,

DataGrid,

Label,

LinkLabel,

Panel,

GroupBox,

PictureBox,

Splitter,

StatusBar,

ToolBar,

TabPage,

** TabControl

Kliknij Kliknij, Kliknij dwukrotnieKliknij Kliknij Kliknij, Kliknij dwukrotnieKliknij Kliknij Kliknij, Kliknij dwukrotnieKliknij Kliknij Kliknij, Kliknij dwukrotnieKliknij Kliknij Kliknij, Kliknij dwukrotnieKliknij

* Wskaźnik myszy musi być nad obiektem podrzędnym (TreeNode lub ListViewItem).

** Obiekt TabControl musi zawierać co najmniej jeden TabPage element w swojej TabPages kolekcji.

Dotyczy

Zobacz też