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 ganda 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 dinaikkan setiap kali kontrol diklik dua kali. Misalnya, jika Anda memiliki penanganan aktivitas untuk Click peristiwa DoubleClickdan Form peristiwa , Click dan DoubleClick peristiwa dinaikkan saat formulir diklik dua kali dan kedua metode dipanggil. Jika kontrol diklik ganda dan kontrol tersebut DoubleClick tidak mendukung peristiwa, Click peristiwa mungkin dinaikkan dua kali.

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

Note

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

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

Catatan Bagi Inheritor

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

Tabel berikut 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 XButton1 Mouse Double-Click XButton2 Klik Mouse Double-Click Mouse XButton2
MonthCalendarBahasa Indonesia:

DateTimePicker,

RichTextBox,

HScrollBar,

VScrollBar

tidak ada

Tidak Tidak Tidak Tidak Tidak Tidak Tidak Tidak Tidak
ButtonBahasa Indonesia:

CheckBox,

RadioButton

Klik

Klik, Klik Tidak Tidak Tidak Tidak Tidak Tidak Tidak Tidak
ListBoxBahasa Indonesia:

CheckedListBox,

ComboBox

Klik

Klik, DoubleClick Tidak Tidak Tidak Tidak Tidak Tidak Tidak Tidak
TextBoxBahasa Indonesia:

DomainUpDown,

NumericUpDown

Klik

Klik, DoubleClick Tidak Tidak Tidak Tidak Tidak Tidak Tidak Tidak
* TreeView,

* ListView

Klik

Klik, DoubleClick Klik Klik, DoubleClick Tidak Tidak Tidak Tidak Tidak Tidak
ProgressBarBahasa Indonesia:

TrackBar

Klik

Klik, Klik Klik Klik, Klik Klik Klik, Klik Klik Klik, Klik Klik Klik, Klik
FormBahasa Indonesia:

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 di atas objek anak (TreeNode atau ListViewItem).

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

Berlaku untuk

Lihat juga