Control.Click Ereignis

Definition

Tritt auf, wenn auf das Steuerelement geklickt wird.

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

Ereignistyp

Beispiele

Das folgende Codebeispiel zeigt das Click Ereignis in einem Ereignishandler.

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

Hinweise

Das Click Ereignis übergibt einen EventArgs Ereignishandler, sodass es nur angibt, dass ein Klick aufgetreten ist. Wenn Sie spezifischere Mausinformationen benötigen (Schaltfläche, Anzahl der Klicks, Raddrehung oder Position), verwenden Sie das MouseClick Ereignis. Das Ereignis wird jedoch nicht ausgelöst, MouseClick wenn der Klick durch eine andere Aktion als die der Maus verursacht wird, z. B. durch Drücken der EINGABETASTE.

Ein Doppelklick wird durch die Mauseinstellungen des Betriebssystems des Benutzers bestimmt. Der Benutzer kann die Zeit zwischen Klicks einer Maustaste festlegen, die als Doppelklick und nicht als zwei Klicks betrachtet werden soll. Das Click Ereignis wird bei jedem Doppelklicken eines Steuerelements ausgelöst. Wenn Sie z. B. Ereignishandler für die Click Und DoubleClick Ereignisse eines Ereignisses Formhaben, werden die Click ereignisse ausgelöst DoubleClick , wenn das Formular mit Doppelklick versehen wird und beide Methoden aufgerufen werden. Wenn auf ein Steuerelement doppelklicken und das Steuerelement das DoubleClick Ereignis nicht unterstützt, wird das Click Ereignis möglicherweise zweimal ausgelöst.

Sie müssen den StandardClick Wert ControlStylestrue für dieses Ereignis festlegen, auf das dieses Ereignis ausgelöst werden soll.

Note

Die folgenden Ereignisse werden nicht für die TabControl Klasse ausgelöst, es sei denn, es gibt mindestens eine TabPage in der TabControl.TabPages Auflistung: Click, , DoubleClickMouseDown, MouseUpMouseHover, MouseEnterund MouseLeaveMouseMove. Wenn mindestens eine TabPage In der Auflistung vorhanden ist und der Benutzer mit der Kopfzeile des Registerkartensteuerelements interagiert (wobei die TabPage Namen angezeigt werden), löst das TabControl entsprechende Ereignis aus. Wenn sich die Benutzerinteraktion jedoch im Clientbereich der Registerkartenseite befindet, löst das TabPage entsprechende Ereignis aus.

Weitere Informationen zur Behandlung von Ereignissen finden Sie unter behandeln und Auslösen von Ereignissen.

Hinweise zu Vererbungen

Erben von einem Standard-Windows Forms-Steuerelement und Ändern des StandardClick oder StandardDoubleClick Werte von ControlStyles in true kann unerwartetes Verhalten verursachen oder überhaupt keine Auswirkung haben, wenn das Steuerelement die Ereignisse Click oder DoubleClick nicht unterstützt.

In der folgenden Tabelle sind Windows Forms Steuerelemente aufgeführt, und welches Ereignis (Click oder DoubleClick) als Reaktion auf die angegebene Mausaktion ausgelöst wird.

Steuerung Linke Maustaste klicken Doppelklick mit der linken Maustaste Rechtsklick Doppelklick mit der rechten Maustaste Mittlerer Mausklick Doppelklick mit der mittleren Maus XButton1 Mouse Click XButton1 Mouse Double-Click XButton2-Mausklick XButton2 Mouse Double-Click
MonthCalendar, , DateTimePickerHScrollBarVScrollBar nichts nichts nichts nichts nichts nichts nichts nichts nichts nichts
Button, , CheckBoxRichTextBoxRadioButton Klicken Sie auf Klicken, klicken Sie auf nichts nichts nichts nichts nichts nichts nichts nichts
ListBox, CheckedListBoxComboBox Klicken Sie auf Click, DoubleClick nichts nichts nichts nichts nichts nichts nichts nichts
TextBox, DomainUpDownNumericUpDown Klicken Sie auf Click, DoubleClick nichts nichts nichts nichts nichts nichts nichts nichts
* TreeView, * ListView Klicken Sie auf Click, DoubleClick Klicken Sie auf Click, DoubleClick nichts nichts nichts nichts nichts nichts
ProgressBar, TrackBar Klicken Sie auf Klicken, klicken Sie auf Klicken Sie auf Klicken, klicken Sie auf Klicken Sie auf Klicken, klicken Sie auf Klicken Sie auf Klicken, klicken Sie auf Klicken Sie auf Klicken, klicken Sie auf
Form, DataGrid, , Label, LinkLabel, PanelGroupBox, PictureBox, , Splitter, , StatusBar, , ToolBar, TabPage**TabControl Klicken Sie auf Click, DoubleClick Klicken Sie auf Click, DoubleClick Klicken Sie auf Click, DoubleClick Klicken Sie auf Click, DoubleClick Klicken Sie auf Click, DoubleClick

* Der Mauszeiger muss sich über einem untergeordneten Objekt (TreeNode oder ListViewItem).

** Das TabControl muss mindestens einen TabPage in seiner TabPages Sammlung haben.

Gilt für:

Weitere Informationen