Control.Click Zdarzenie

Definicja

Występuje po kliknięciu kontrolki.

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

Typ zdarzenia

Przykłady

Poniższy przykład kodu przedstawia Click zdarzenie w procedurze obsługi zdarzeń.

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

Uwagi

Zdarzenie Click przekazuje element EventArgs do procedury obsługi zdarzeń, dlatego wskazuje tylko, że wystąpiło kliknięcie. Jeśli potrzebujesz bardziej szczegółowych informacji o myszach (przycisk, liczba kliknięć, obracanie kół lub lokalizacja), użyj MouseClick zdarzenia. Jednak zdarzenie nie zostanie podniesione, MouseClick jeśli kliknięcie jest spowodowane przez akcję inną niż mysz, na przykład naciśnięcie klawisza ENTER.

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óry powinien być uznawany 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 zdarzeń Form, Click i DoubleClick są wywoływane, gdy formularz jest dwukrotnie klikany, a obie metody są wywoływane. Jeśli kontrolka jest dwukrotnie kliknięta i ta kontrolka nie obsługuje DoubleClick zdarzenia, Click zdarzenie może zostać podniesione dwukrotnie.

Musisz ustawić StandardClicktrue wartość na wartość ControlStyles dla tego zdarzenia, które ma zostać podniesione.

Uwaga

Następujące zdarzenia nie są wywoływane dla TabControl klasy, chyba że istnieje co najmniej jeden TabPage w TabControl.TabPages kolekcji: Click, , MouseDownMouseHoverMouseUpMouseEnterDoubleClicki . MouseLeaveMouseMove 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 strony karty, TabPage zgłasza to zdarzenie.

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

Uwagi do dziedziczy

Dziedziczenie ze standardowej kontrolki Windows Forms i zmienianie StandardClick wartości lub StandardDoubleClick w ControlStyles celu true może spowodować 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 jakie zdarzenie (Clicklub DoubleClick) jest wywoływane w odpowiedzi na akcję myszy.

Kontrola Kliknięcie lewym przyciskiem myszy Kliknij dwukrotnie lewą myszą Kliknięcie prawym przyciskiem myszy Kliknij dwukrotnie prawym przyciskiem myszy Środkowe kliknięcie myszą Kliknij dwukrotnie środkową mysz Kliknięcie myszy XButton1 Double-Click myszy XButton1 Kliknięcie myszy XButton2 Double-Click myszy XButton2
MonthCalendar, DateTimePicker, HScrollBar, VScrollBar brak brak brak brak brak brak brak brak brak brak
Button, CheckBox, RichTextBox, 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ż