Freigeben über


Control.Click-Ereignis

Tritt beim Klicken auf das Steuerelement ein.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
Public Event Click As EventHandler
'Usage
Dim instance As Control
Dim handler As EventHandler

AddHandler instance.Click, handler
public event EventHandler Click
public:
event EventHandler^ Click {
    void add (EventHandler^ value);
    void remove (EventHandler^ value);
}
/** @event */
public void add_Click (EventHandler value)

/** @event */
public void remove_Click (EventHandler value)
JScript unterstützt die Verwendung von Ereignissen, aber nicht die Deklaration von neuen Ereignissen.

Hinweise

Das Click-Ereignis übergibt ein EventArgs an den Ereignishandler, in dem nur mitgeteilt wird, dass ein Mausklick erfolgt ist. Wenn Sie ausführlichere Mausinformationen benötigen (Taste, Anzahl der Mausklicks, Mausraddrehungen oder Position), verwenden Sie das MouseClick-Ereignis. Das MouseClick-Ereignis wird jedoch nicht ausgelöst, wenn der Mausklick nicht von einer Mausaktion verursacht wurde, sondern z. B. durch Drücken der EINGABETASTE.

Ein Doppelklick wird durch die Mauseinstellungen des Betriebssystems des Benutzers bestimmt. Der Benutzer kann den Zeitraum festlegen, innerhalb dessen der zweite Mausklick erfolgen muss, damit zwei aufeinander folgende Mausklicks als Doppelklick erkannt werden. Bei jedem Doppelklick auf ein Steuerelement wird das Click-Ereignis ausgelöst. Wenn Sie z. B. über einen Ereignishandler für das Click-Ereignis und für das DoubleClick-Ereignis eines Form verfügen, wird das Click-Ereignis und das DoubleClick-Ereignis ausgelöst, wenn auf das Formular doppelgeklickt wird und beide Methoden aufgerufen werden. Bei einem Doppelklick auf ein Steuerelement, das das DoubleClick-Ereignis nicht unterstützt, wird das Click-Ereignis möglicherweise zweimal ausgelöst.

Damit dieses Ereignis ausgelöst wird, müssen Sie den StandardClick-Wert von ControlStyles auf true festlegen.

Hinweis

Die folgenden Ereignisse werden nur dann für die TabControl-Klasse ausgelöst, wenn mindestens eine TabPage in der TabControl.TabPages-Auflistung enthalten ist: Click, DoubleClick, MouseDown, MouseUp, MouseHover, MouseEnter, MouseLeave und MouseMove. Wenn sich mindestens eine TabPage in der Auflistung befindet und eine Benutzerinteraktion für den Header des Registersteuerelements (den Bereich, in dem die TabPage-Namen angezeigt werden) stattfindet, löst das TabControl das entsprechende Ereignis aus. Wenn die Benutzerinteraktion jedoch im Clientbereich der Registerkarte erfolgt, löst die TabPage das entsprechende Ereignis aus.

Weitere Informationen zum Behandeln von Ereignissen finden Sie unter Behandeln von Ereignissen.

Hinweise für Erben Das Erben von einem Windows Forms-Standardsteuerelement und das Ändern des StandardClick-Werts oder des StandardDoubleClick-Werts von ControlStyles in true kann zu unerwartetem Verhalten führen oder keine Auswirkungen haben, wenn das Steuerelement das Click-Ereignis und das DoubleClick-Ereignis nicht unterstützt. In der folgenden Tabelle werden Windows Forms-Steuerelemente mit den Ereignissen (Click oder DoubleClick) aufgelistet, die bei der angegebenen Mausaktion ausgelöst werden.

Steuerelement

Klicken mit der linken Maustaste

Doppelklicken mit der linken Maustaste

Klicken mit der rechten Maustaste

Doppelklicken mit der rechten Maustaste

Klicken mit der mittleren Maustaste

Doppelklicken mit der mittleren Maustaste

Klicken mit der Maustaste XButton1

Doppelklicken mit der Maustaste XButton1

Klicken mit der Maustaste XButton2

Doppelklicken mit der Maustaste XButton2

MonthCalendar,

DateTimePicker,

HScrollBar,

VScrollBar

Keine

Keine

Keine

Keine

Keine

Keine

Keine

Keine

Keine

Keine

Button,

CheckBox,

RichTextBox,

RadioButton

Klick

Zwei Klicks

Keine

Keine

Keine

Keine

Keine

Keine

Keine

Keine

ListBox,

CheckedListBox,

ComboBox

Click

Click, DoubleClick

Keine

Keine

Keine

Keine

Keine

Keine

Keine

Keine

TextBox,

DomainUpDown,

NumericUpDown

Click

Click, DoubleClick

Keine

Keine

Keine

Keine

Keine

Keine

Keine

Keine

* TreeView,

* ListView

Click

Click, DoubleClick

Click

Click, DoubleClick

Keine

Keine

Keine

Keine

Keine

Keine

ProgressBar,

TrackBar

Click

Click, Click

Click

Click, Click

Click

Click, Click

Click

Click, Click

Click

Click, Click

Form,

DataGrid,

Label,

LinkLabel,

Panel,

GroupBox,

PictureBox,

Splitter,

StatusBar,

ToolBar,

TabPage,

** TabControl

Click

Click, DoubleClick

Click

Click, DoubleClick

Click

Click, DoubleClick

Click

Click, DoubleClick

Click

Click, DoubleClick

* Der Mauszeiger muss sich über einem untergeordneten Objekt befinden (TreeNode oder ListViewItem). ** TabControl muss mindestens über eine TabPage in der TabPages-Auflistung verfügen.

Beispiel

Im folgenden Codebeispiel wird das Click-Ereignis in einem Ereignishandler veranschaulicht.

' 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
// 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 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.get_Parent();

    // Set the text and backcolor of the parent control.
    control.set_Text("My Groupbox");
    control.set_BackColor(Color.get_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.set_Text("The Form of My Control");
    myForm.set_BackColor(Color.get_Red());
} //button1_Click

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

Control-Klasse
Control-Member
System.Windows.Forms-Namespace
OnClick
StandardClick
MouseClick
DoubleClick
MouseDoubleClick