Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Control.Click Event

Occurs when the control is clicked.

[Visual Basic]
Public Event Click As EventHandler
[C#]
public event EventHandler Click;
[C++]
public: __event EventHandler* Click;

[JScript] In JScript, you can handle the events defined by a class, but you cannot define your own.

Event Data

The event handler receives an argument of type EventArgs.

Remarks

The Click event passes an EventArgs object to its event handler, so it only indicates that a click has occurred. If you need more specific mouse information (button, number of clicks, wheel rotation, or location), use the MouseDown and MouseUp events which pass a MouseEventArgs object to the event handler.

A double-click is determined by the mouse settings of the user's operating system. The user can set the time between clicks of a mouse button that should be considered a double-click rather than two clicks. The Click event is raised every time a control is double-clicked. For example, if you have an event-handling methods for the Click and DoubleClick events of a Form, the Click and DoubleClick events are raised when the form is double-clicked and both methods are called. If a control is double-clicked and that control does not support the DoubleClick event, the Click event might be raised twice.

The ControlStyles.StandardClick style bit must be set to true for this event to be raised.

Notes to Inheritors:  Inheriting from a standard Windows Forms control and changing the StandardClick or StandardDoubleClick bit values to true can cause unexpected behavior or have no effect at all if the control does not support the Click or DoubleClick events.

The following table lists Windows Forms controls and which event (Click or DoubleClick) is raised in response to the mouse action specified.

Control Left Mouse Click Left Mouse Double Click Right Mouse Click Right Mouse Double Click Middle Mouse Click Middle Mouse Double Click XButton1 Mouse Click XButton1 Mouse Double-Click XButton2 Mouse Click XButton2 Mouse Double-Click
MonthCalendar,

DateTimePicker,

RichTextBox,

HScrollBar,

VScrollBar

none none none none none none none none none none
Button,

CheckBox,

RadioButton

Click Click, Click none none none none none none none none
ListBox,

CheckedListBox,

ComboBox

Click Click, DoubleClick none none none none none none none none
TextBox,

DomainUpDown,

NumericUpDown

Click Click, DoubleClick none none none none none none none none
* TreeView,

* ListView

Click Click, DoubleClick Click Click, DoubleClick none none none none none none
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

* The mouse pointer must be over a child object (TreeNode or ListViewItem).

** The TabControl must have at least one TabPage in its TabPages collection.

Note   The following events are not raised for the TabControl class unless there is at least one TabPage in the TabControl.TabPages collection: Click, DoubleClick, MouseDown, MouseUp, MouseHover, MouseEnter, MouseLeave and MouseMove. If there is at least one TabPage in the collection, and the user interacts with the tab controls header (where the TabPage names appear), the TabControl raises the appropriate event. However, if the user interaction is within the client area of the tab page, the TabPage raises the appropriate event.

For more information about handling events, see Consuming Events.

Example

[Visual Basic] 
' 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 handling 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

[C#] 
// 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 handling 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;
}

[C++] 
// 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 handling 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 = S"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 = S"The Form of My Control";
   myForm->BackColor = Color::Red;
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Control Class | Control Members | System.Windows.Forms Namespace | OnClick | StandardClick

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft