Control.DoubleClick Kejadian

Definisi

Terjadi ketika kontrol diklik dua kali.

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

Jenis Acara

Contoh

Contoh kode berikut menggunakan DoubleClick peristiwa untuk memuat file teks yang ListBox tercantum dalam ListBox kontrol 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

Keterangan

Klik dua kali ditentukan oleh pengaturan mouse sistem operasi pengguna. Pengguna dapat mengatur waktu antara klik tombol mouse yang harus dianggap klik ganda daripada dua klik. Peristiwa Click dimunculkan setiap kali kontrol diklik dua kali. Misalnya, jika Anda memiliki penanganan aktivitas untuk Click peristiwa dan DoubleClick dari Form, Click peristiwa dan DoubleClick dimunculkan saat formulir diklik dua kali dan kedua metode dipanggil. Jika kontrol diklik dua kali dan kontrol tersebut DoubleClickClick tidak mendukung peristiwa, peristiwa mungkin dinaikkan dua kali.

Anda harus mengatur StandardDoubleClick nilai ControlStyles dan StandardClick ke true agar acara ini dimunculkan. Nilai-nilai ini mungkin sudah diatur ke true jika Anda mewarisi dari kontrol Formulir Windows yang ada.

Catatan

Peristiwa berikut tidak dinaikkan untuk TabControl kelas kecuali setidaknya ada satu TabPage dalam TabControl.TabPages koleksi: Click, , DoubleClick, MouseUpMouseDown, MouseHover, MouseEnter, MouseLeave dan MouseMove. Jika setidaknya ada satu TabPage dalam koleksi, dan pengguna berinteraksi dengan header kontrol tab (di mana TabPage nama muncul), meningkatkan TabControl peristiwa yang sesuai. Namun, jika interaksi pengguna berada dalam area klien halaman tab, akan TabPage meningkatkan peristiwa yang sesuai.

Untuk informasi selengkapnya tentang menangani peristiwa, lihat Menangani dan Menaikkan Peristiwa.

Catatan Bagi Inheritor

Mewarisi dari kontrol Formulir Windows standar dan mengubah StandardClick nilai ControlStyles atau StandardDoubleClick menjadi true dapat menyebabkan perilaku yang tidak terduga atau tidak berpengaruh sama sekali jika kontrol tidak mendukung Click atau DoubleClick peristiwa.

Tabel berikut ini mencantumkan kontrol Formulir Windows dan peristiwa mana (Click atau DoubleClick) yang dinaikkan sebagai respons terhadap tindakan mouse yang ditentukan.

Kontrol Klik Kiri Mouse Klik Ganda Mouse Kiri Klik Kanan Mouse Klik Ganda Mouse Kanan Klik Mouse Tengah Klik Ganda Mouse Tengah XButton1 Klik Mouse Double-Click Tetikus XButton1 Klik Tetikus XButton2 Double-Click Tetikus XButton2
MonthCalendar,

DateTimePicker,

RichTextBox,

HScrollBar,

VScrollBar

tidak ada tidak ada tidak ada tidak ada tidak ada tidak ada tidak ada tidak ada tidak ada tidak ada
Button,

CheckBox,

RadioButton

Klik Klik, Klik tidak ada tidak ada tidak ada tidak ada tidak ada tidak ada tidak ada tidak ada
ListBox,

CheckedListBox,

ComboBox

Klik Klik, DoubleClick tidak ada tidak ada tidak ada tidak ada tidak ada tidak ada tidak ada tidak ada
TextBox,

DomainUpDown,

NumericUpDown

Klik Klik, DoubleClick tidak ada tidak ada tidak ada tidak ada tidak ada tidak ada tidak ada tidak ada
* TreeView,

* ListView

Klik Klik, DoubleClick Klik Klik, DoubleClick tidak ada tidak ada tidak ada tidak ada tidak ada tidak ada
ProgressBar,

TrackBar

Klik Klik, Klik Klik Klik, Klik Klik Klik, Klik Klik Klik, Klik Klik Klik, Klik
Form,

DataGrid,

Label,

LinkLabel,

Panel,

GroupBox,

PictureBox,

Splitter,

StatusBar,

ToolBar,

TabPage,

** TabControl

Klik Klik, DoubleClick Klik Klik, DoubleClick Klik Klik, DoubleClick Klik Klik, DoubleClick Klik Klik, DoubleClick

* Penunjuk mouse harus melebihi objek anak (TreeNode atau ListViewItem).

** Harus TabControl memiliki setidaknya satu TabPage dalam koleksinya TabPages .

Berlaku untuk

Lihat juga