Control.Click Esemény
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Akkor fordul elő, ha a vezérlőre kattint.
public:
event EventHandler ^ Click;
public event EventHandler Click;
public event EventHandler? Click;
member this.Click : EventHandler
Public Custom Event Click As EventHandler
Eseménytípus
Példák
Az alábbi példakód egy Click eseménykezelő eseményét mutatja be.
// 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
Megjegyzések
Az Click esemény átad egy eseménykezelőnek EventArgs , így csak azt jelzi, hogy kattintás történt. Ha konkrétabb egérinformációkra (gomb, kattintások száma, kerékforgatás vagy hely) van szüksége, használja az eseményt MouseClick . Az esemény azonban nem lesz aktiválva, MouseClick ha a kattintást nem az egér művelete okozza, például az ENTER billentyű lenyomása.
A dupla kattintást a felhasználó operációs rendszerének egérbeállításai határozzák meg. A felhasználó beállíthatja az egérgombok kattintásai közötti időt, amelyet két kattintás helyett dupla kattintásnak kell tekinteni. Az Click esemény minden alkalommal létre lesz hozva, amikor a vezérlőre duplán kattint. Ha például egy adott esemény eseménykezelőivel ClickDoubleClick rendelkezik, a rendszer az Form űrlap duplán kattintásával és Click mindkét metódus meghívásával DoubleClickelőhozza az eseményeket. Ha egy vezérlőre duplán kattint, és ez a vezérlő nem támogatja az DoubleClick eseményt, előfordulhat, hogy az Click esemény kétszer lesz előállítva.
Ennek az eseménynek az StandardClick értékét ControlStylestrue meg kell adnia a megemelendő eseményhez.
Note
A következő események csak akkor kerülnek elő az TabControl osztály számára, ha legalább egy TabPage van a TabControl.TabPages gyűjteményben: Click, , DoubleClick, MouseDownMouseUp, MouseHover, MouseEnterMouseLeave és MouseMove. Ha legalább egy TabPage van a gyűjteményben, és a felhasználó a tabulátor fejlécével lép kapcsolatba (ahol a TabPage nevek megjelennek), a TabControl megfelelő esemény keletkezik. Ha azonban a felhasználói interakció a lap ügyfélterületén belül van, a TabPage megfelelő eseményt aktiválja.
Az események kezelésével kapcsolatos további információkért lásd : Események kezelése és emelése.
Jegyzetek öröklőknek
A standard Windows Forms vezérlőelemtől való öröklődés és a StandardClick vagy StandardDoubleClick értékek ControlStyles értékének true módosítása váratlan viselkedést okozhat, vagy egyáltalán nincs hatása, ha a vezérlő nem támogatja a Click vagy DoubleClick eseményeket.
Az alábbi táblázat felsorolja Windows Forms vezérlőket, és azt, hogy melyik esemény (Click vagy DoubleClick) kerül sor a megadott egérműveletre válaszul.
| Ellenőrzés | Bal egérkattintás | Bal egér dupla kattintással | Kattintson a jobb egérgombbal | Kattintson duplán a jobb egérgombbal | Közép egérkattintás | Középső egér dupla kattintással | XButton1 egérkattintás | XButton1 egér Double-Click | XButton2 egérkattintás | XButton2 egér Double-Click |
|---|---|---|---|---|---|---|---|---|---|---|
| MonthCalendar, DateTimePicker, HScrollBarVScrollBar | Nincs | Nincs | Nincs | Nincs | Nincs | Nincs | Nincs | Nincs | Nincs | Nincs |
| Button, CheckBox, RichTextBoxRadioButton | Kattintás | Kattintson, kattintson a | Nincs | Nincs | Nincs | Nincs | Nincs | Nincs | Nincs | Nincs |
| \ |
Kattintás | Kattintson a DoubleClick parancsra | Nincs | Nincs | Nincs | Nincs | Nincs | Nincs | Nincs | Nincs |
| \ |
Kattintás | Kattintson a DoubleClick parancsra | Nincs | Nincs | Nincs | Nincs | Nincs | Nincs | Nincs | Nincs |
| * TreeView, * ListView | Kattintás | Kattintson a DoubleClick parancsra | Kattintás | Kattintson a DoubleClick parancsra | Nincs | Nincs | Nincs | Nincs | Nincs | Nincs |
| ProgressBar, TrackBar | Kattintás | Kattintson, kattintson a | Kattintás | Kattintson, kattintson a | Kattintás | Kattintson, kattintson a | Kattintás | Kattintson, kattintson a | Kattintás | Kattintson, kattintson a |
| Form, DataGrid, Label, LinkLabel, PanelGroupBox, PictureBox, Splitter, StatusBar, ToolBar, TabPage**TabControl | Kattintás | Kattintson a DoubleClick parancsra | Kattintás | Kattintson a DoubleClick parancsra | Kattintás | Kattintson a DoubleClick parancsra | Kattintás | Kattintson a DoubleClick parancsra | Kattintás | Kattintson a DoubleClick parancsra |
* Az egérmutatónak gyermekobjektum (TreeNode vagy ListViewItem) fölött kell lennie.
** A TabControl gyűjteményben legalább egynek TabPage rendelkeznie TabPages kell.