Control.Click Gebeurtenis
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Treedt op wanneer op het besturingselement wordt geklikt.
public:
event EventHandler ^ Click;
public event EventHandler Click;
public event EventHandler? Click;
member this.Click : EventHandler
Public Custom Event Click As EventHandler
Gebeurtenistype
Voorbeelden
In het volgende codevoorbeeld ziet u de Click gebeurtenis in een gebeurtenis-handler.
// 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
Opmerkingen
De Click gebeurtenis geeft een EventArgs door aan de gebeurtenis-handler, zodat alleen wordt aangegeven dat er een klik is opgetreden. Als u specifieke informatie over de muis nodig hebt (knop, aantal klikken, wielrotatie of locatie), gebruikt u de MouseClick gebeurtenis. De MouseClick gebeurtenis wordt echter niet gegenereerd als de klik wordt veroorzaakt door een andere actie dan die van de muis, zoals het drukken op de Enter-toets.
Een dubbelklik wordt bepaald door de muisinstellingen van het besturingssysteem van de gebruiker. De gebruiker kan de tijd instellen tussen klikken van een muisknop die moet worden beschouwd als een dubbelklik in plaats van twee klikken. De Click gebeurtenis wordt gegenereerd telkens wanneer er op een besturingselement wordt gedubbelklikt. Als u bijvoorbeeld gebeurtenis-handlers hebt voor de Click en DoubleClick gebeurtenissen van een Form, worden de Click en DoubleClick gebeurtenissen gegenereerd wanneer op het formulier wordt gedubbelklikt en beide methoden worden aangeroepen. Als er op een besturingselement wordt gedubbelklikt en dat besturingselement de DoubleClick gebeurtenis niet ondersteunt, kan de Click gebeurtenis twee keer worden gegenereerd.
U moet de StandardClick waarde instellen op ControlStylestrue voor deze gebeurtenis die moet worden gegenereerd.
Note
De volgende gebeurtenissen worden niet voor de TabControl klasse gegenereerd, tenzij er ten minste één TabPage in de TabControl.TabPages verzameling staat: Click, , DoubleClickMouseDown, MouseUp, , MouseHoveren MouseEnterMouseLeaveMouseMove. Als er ten minste één TabPage in de verzameling staat en de gebruiker communiceert met de koptekst van het tabblad besturingselement (waar de TabPage namen worden weergegeven), wordt de TabControl juiste gebeurtenis gegenereerd. Als de interactie van de gebruiker zich echter binnen het clientgebied van de tabbladpagina bevindt, wordt de TabPage juiste gebeurtenis gegenereerd.
Zie Gebeurtenissen verwerken en genereren voor meer informatie over het afhandelen van gebeurtenissen.
Notities voor overnemers
Overnemen van een standaard Windows Forms besturingselement en het wijzigen van de StandardClick of StandardDoubleClick waarden van ControlStyles in true kan onverwacht gedrag veroorzaken of helemaal geen effect hebben als het besturingselement de Click of DoubleClick gebeurtenissen niet ondersteunt.
De volgende tabel bevat Windows Forms besturingselementen en welke gebeurtenis (Click of DoubleClick) wordt gegenereerd als reactie op de opgegeven muisactie.
| Beheersing | Klik met de linkermuisknop | Dubbelklik met linkermuis | Klik met de rechtermuisknop | Dubbelklik met de rechtermuisknop | Middelste muisklik | Middelste muis dubbelklikken | XButton1-muisklik | XButton1-muis Double-Click | XButton2-muisklik | XButton2-muis Double-Click |
|---|---|---|---|---|---|---|---|---|---|---|
| MonthCalendar,DateTimePicker,HScrollBar,VScrollBar | none | none | none | none | none | none | none | none | none | none |
| Button,CheckBox,RichTextBox,RadioButton | Klikt u op | Klik, klik op | none | none | none | none | none | none | none | none |
| ListBox, , CheckedListBoxComboBox | Klikt u op | Klik, DoubleClick | none | none | none | none | none | none | none | none |
| TextBox, , DomainUpDownNumericUpDown | Klikt u op | Klik, DoubleClick | none | none | none | none | none | none | none | none |
| * TreeView, * ListView | Klikt u op | Klik, DoubleClick | Klikt u op | Klik, DoubleClick | none | none | none | none | none | none |
| ProgressBar, TrackBar | Klikt u op | Klik, klik op | Klikt u op | Klik, klik op | Klikt u op | Klik, klik op | Klikt u op | Klik, klik op | Klikt u op | Klik, klik op |
| Form, , DataGridLabel, LinkLabel, , Panel, , GroupBox, PictureBoxSplitter, , StatusBar, ToolBar, TabPage**TabControl | Klikt u op | Klik, DoubleClick | Klikt u op | Klik, DoubleClick | Klikt u op | Klik, DoubleClick | Klikt u op | Klik, DoubleClick | Klikt u op | Klik, DoubleClick |
* De muis aanwijzer moet boven een onderliggend object (TreeNode of ListViewItem) staan.
** De TabControl verzameling moet ten minste één TabPage bevatten TabPages .