Control.Click Zdarzenie
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
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 (przycisku, liczby kliknięć, rotacji kół lub lokalizacji), użyj MouseClick zdarzenia. Jednak zdarzenie nie zostanie podniesione, MouseClick jeśli kliknięcie jest spowodowane akcją inną niż mysz, na przykład naciśnięciem klawisza ENTER.
Dwukrotne kliknięcie zależy od ustawień myszy systemu operacyjnego użytkownika. Użytkownik może ustawić czas między kliknięciami przycisku myszy, który powinien zostać uznany 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ń DoubleClicki Form zdarzenia , 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ć zgłoszone dwa razy.
Należy ustawić StandardClick wartość ControlStyles na , aby true to zdarzenie zostało podniesione.
Note
Następujące zdarzenia nie są wywoływane dla TabControl klasy, chyba że istnieje co najmniej jeden TabPage w TabControl.TabPages kolekcji: Click, , , DoubleClickMouseDownMouseUp, MouseHover, MouseEnter, MouseLeave 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 zgłasza odpowiednie zdarzenie.
Aby uzyskać więcej informacji na temat obsługi zdarzeń, zobacz Obsługa i wywoływanie zdarzeń.
Uwagi do dziedziczenia
Dziedziczenie ze standardowej kontrolki Windows Forms i zmiana StandardClick lub StandardDoubleClick wartości ControlStyles na true może spowodować nieoczekiwane zachowanie lub nie ma żadnego wpływu, jeśli kontrolka nie obsługuje Click lub DoubleClick zdarzeń.
W poniższej tabeli wymieniono kontrolki Windows Forms i które zdarzenie (Click lub DoubleClick) jest wywoływane w odpowiedzi na akcję myszy określoną.
| Kontrola | Kliknięcie lewym przyciskiem myszy | Kliknij dwukrotnie lewą myszą | Kliknięcie prawym przyciskiem myszy | Dwukrotne kliknięcie prawym przyciskiem myszy | Środkowe kliknięcie myszą | Kliknij dwukrotnie środkową mysz | XButton1 Kliknij myszą | Double-Click myszy XButton1 | XButton2 Kliknięcie myszą | Double-Click myszy XButton2 |
|---|---|---|---|---|---|---|---|---|---|---|
| MonthCalendar, , DateTimePicker, , HScrollBarVScrollBar | żadne | żadne | żadne | żadne | żadne | żadne | żadne | żadne | żadne | żadne |
| Button, , CheckBox, , RichTextBoxRadioButton | Kliknij pozycję | Kliknij, kliknij | żadne | żadne | żadne | żadne | żadne | żadne | żadne | żadne |
| ListBox, , CheckedListBoxComboBox | Kliknij pozycję | Kliknij, Kliknij dwukrotnieKliknij | żadne | żadne | żadne | żadne | żadne | żadne | żadne | żadne |
| TextBox, , DomainUpDownNumericUpDown | Kliknij pozycję | Kliknij, Kliknij dwukrotnieKliknij | żadne | żadne | żadne | żadne | żadne | żadne | żadne | żadne |
| * TreeView, * ListView | Kliknij pozycję | Kliknij, Kliknij dwukrotnieKliknij | Kliknij pozycję | Kliknij, Kliknij dwukrotnieKliknij | żadne | żadne | żadne | żadne | żadne | żadne |
| ProgressBar, TrackBar | Kliknij pozycję | Kliknij, kliknij | Kliknij pozycję | Kliknij, kliknij | Kliknij pozycję | Kliknij, kliknij | Kliknij pozycję | Kliknij, kliknij | Kliknij pozycję | Kliknij, kliknij |
| Form, DataGrid, LabelLinkLabelPanelGroupBoxPictureBoxSplitterStatusBarToolBarTabPage**TabControl | Kliknij pozycję | Kliknij, Kliknij dwukrotnieKliknij | Kliknij pozycję | Kliknij, Kliknij dwukrotnieKliknij | Kliknij pozycję | Kliknij, Kliknij dwukrotnieKliknij | Kliknij pozycję | Kliknij, Kliknij dwukrotnieKliknij | Kliknij pozycję | Kliknij, Kliknij dwukrotnieKliknij |
* Wskaźnik myszy musi być nad obiektem podrzędnym (TreeNode lub ListViewItem).
** Element TabControl musi zawierać co najmniej jeden TabPage element w swojej TabPages kolekcji.