Control.Click Kejadian

Definisi

Terjadi ketika kontrol diklik.

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

Jenis Acara

Contoh

Contoh kode berikut menunjukkan Click peristiwa dalam penanganan aktivitas.

   // This example uses the Parent property and the Find method of Control to set
   // properties on the parent control of a Button and its Form. The example assumes
   // that a Button control named button1 is located within a GroupBox control. The 
   // example also assumes that the Click event of the Button control is connected to
   // the event handler method defined in the example.
private:
   void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      // Get the control the Button control is located in. In this case a GroupBox.
      Control^ control = button1->Parent;
      
      // Set the text and backcolor of the parent control.
      control->Text = "My Groupbox";
      control->BackColor = Color::Blue;
      
      // Get the form that the Button control is contained within.
      Form^ myForm = button1->FindForm();
      
      // Set the text and color of the form containing the Button.
      myForm->Text = "The Form of My Control";
      myForm->BackColor = Color::Red;
   }
// This example uses the Parent property and the Find method of Control to set
// properties on the parent control of a Button and its Form. The example assumes
// that a Button control named button1 is located within a GroupBox control. The 
// example also assumes that the Click event of the Button control is connected to
// the event handler method defined in the example.
private void button1_Click(object sender, System.EventArgs e)
{
   // Get the control the Button control is located in. In this case a GroupBox.
   Control control = button1.Parent;
   // Set the text and backcolor of the parent control.
   control.Text = "My Groupbox";
   control.BackColor = Color.Blue;
   // Get the form that the Button control is contained within.
   Form myForm = button1.FindForm();
   // Set the text and color of the form containing the Button.
   myForm.Text = "The Form of My Control";
   myForm.BackColor = Color.Red;
}
' This example uses the Parent property and the Find method of Control to set
' properties on the parent control of a Button and its Form. The example assumes
' that a Button control named button1 is located within a GroupBox control. The 
' example also assumes that the Click event of the Button control is connected to
' the event handler method defined in the example.
Private Sub button1_Click(sender As Object, e As System.EventArgs) Handles button1.Click
   ' Get the control the Button control is located in. In this case a GroupBox.
   Dim control As Control = button1.Parent
   ' Set the text and backcolor of the parent control.
   control.Text = "My Groupbox"
   control.BackColor = Color.Blue
   ' Get the form that the Button control is contained within.
   Dim myForm As Form = button1.FindForm()
   ' Set the text and color of the form containing the Button.
   myForm.Text = "The Form of My Control"
   myForm.BackColor = Color.Red
End Sub

Keterangan

Kejadian Click meneruskan EventArgs ke penanganan aktivitasnya, sehingga hanya menunjukkan bahwa klik telah terjadi. Jika Anda memerlukan informasi mouse yang lebih spesifik (tombol, jumlah klik, rotasi roda, atau lokasi), gunakan peristiwa tersebut MouseClick . Namun, MouseClick peristiwa tidak akan dinaikkan jika klik disebabkan oleh tindakan selain mouse, seperti menekan tombol ENTER.

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 dimunculkan setiap kali kontrol diklik dua kali. Misalnya, jika Anda memiliki penanganan aktivitas untuk Click peristiwa dan DoubleClick dari Form, ClickDoubleClick dan peristiwa dinaikkan 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 StandardClick nilai ControlStyles ke true agar kejadian ini dinaikkan.

Catatan

Peristiwa berikut tidak dinaikkan untuk TabControl kelas kecuali setidaknya ada satu TabPage dalam TabControl.TabPages koleksi: Click, , DoubleClick, MouseDown, MouseUpMouseHover, 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 di dalam area klien halaman tab, akan TabPage muncul peristiwa yang sesuai.

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

Catatan untuk pewaris

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 ClickDoubleClick atau 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 Klik Tetikus XButton1 Double-Click Tetikus XButton1 Klik Tetikus XButton2 Double-Click Tetikus XButton2
MonthCalendar, DateTimePicker, HScrollBar, VScrollBar tidak ada tidak ada tidak ada tidak ada tidak ada tidak ada tidak ada tidak ada tidak ada tidak ada
Button, CheckBox, RichTextBox, 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