Control.Click Control.Click Control.Click Control.Click Event

定义

在单击控件时发生。Occurs when the control is clicked.

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

示例

下面的代码示例演示Click事件处理程序中的事件。The following code example shows the Click event in an event 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

注解

Click事件将传递EventArgs给其事件处理程序,因此它仅指示发生了单击操作。The Click event passes an EventArgs to its event handler, so it only indicates that a click has occurred. 如果需要更具体的鼠标信息 (按钮、 单击次数、 鼠标轮旋转或位置),使用MouseClick事件。If you need more specific mouse information (button, number of clicks, wheel rotation, or location), use the MouseClick event. 但是,MouseClick如果导致单击的操作不是鼠标,例如,按下 ENTER 键操作,将不会引发事件。However, the MouseClick event will not be raised if the click is caused by action other than that of the mouse, such as pressing the ENTER key.

由用户的操作系统的鼠标设置确定一次双击。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. Click每次双击控件时引发事件。The Click event is raised every time a control is double-clicked. 例如,如果有事件处理程序ClickDoubleClick的事件Form,则ClickDoubleClick时双击窗体之后,并调用这两种方法将引发事件。For example, if you have event handlers 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. 如果双击控件时,控件不支持DoubleClick事件,Click可能两次引发事件。If a control is double-clicked and that control does not support the DoubleClick event, the Click event might be raised twice.

必须设置StandardClick的值ControlStylestrue引发此事件。You must set the StandardClick value of ControlStyles to true for this event to be raised.

备注

不会引发以下事件TabControl类,除非没有至少一个TabPageTabControl.TabPages集合: ClickDoubleClickMouseDownMouseUpMouseHoverMouseEnterMouseLeaveMouseMoveThe 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. 如果没有至少一个TabPage在集合中,并在用户与选项卡控件的标头交互 (其中TabPage名称显示),则TabControl引发相应事件。If there is at least one TabPage in the collection, and the user interacts with the tab control's header (where the TabPage names appear), the TabControl raises the appropriate event. 但是,如果在工作区内的选项卡页上,为用户交互TabPage引发相应事件。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 Handling and Raising Events.

继承者说明Notes to inheritors

从标准 Windows 窗体控件继承并更改StandardClickStandardDoubleClick的值ControlStylestrue会导致意外的行为或根本不起任何作用,如果该控件不支持ClickDoubleClick事件。Inheriting from a standard Windows Forms control and changing the StandardClick or StandardDoubleClick values of ControlStyles to true can cause unexpected behavior or have no effect at all if the control does not support the Click or DoubleClick events.

下表列出了 Windows 窗体控件和哪个事件 (ClickDoubleClick) 到指定的鼠标操作的响应中引发。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 鼠标单击XButton1 Mouse Click 双击 XButton1 鼠标XButton1 Mouse Double-Click XButton2 鼠标单击XButton2 Mouse Click XButton2 鼠标双击XButton2 Mouse Double-Click
MonthCalendar, DateTimePicker, HScrollBar, VScrollBarMonthCalendar, DateTimePicker, HScrollBar, VScrollBar none none none none none none none none none none
Button, CheckBox, RichTextBox, RadioButtonButton, CheckBox, RichTextBox, RadioButton 单击Click 单击,然后单击Click, Click none none none none none none none none
ListBox, CheckedListBox, ComboBoxListBox, CheckedListBox, ComboBox 单击Click Click, DoubleClickClick, DoubleClick none none none none none none none none
TextBox, DomainUpDown, NumericUpDownTextBox, DomainUpDown, NumericUpDown 单击Click Click, DoubleClickClick, DoubleClick none none none none none none none none
* TreeView, * ListView* TreeView, * ListView 单击Click Click, DoubleClickClick, DoubleClick 单击Click Click, DoubleClickClick, DoubleClick none none none none none none
ProgressBarTrackBarProgressBar, 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, ** TabControlForm, DataGrid, Label, LinkLabel, Panel, GroupBox, PictureBox, Splitter, StatusBar, ToolBar, TabPage, ** TabControl 单击Click Click, DoubleClickClick, DoubleClick 单击Click Click, DoubleClickClick, DoubleClick 单击Click Click, DoubleClickClick, DoubleClick 单击Click Click, DoubleClickClick, DoubleClick 单击Click Click, DoubleClickClick, DoubleClick

* 鼠标指针必须位于一个子对象 (TreeNodeListViewItem)。* The mouse pointer must be over a child object (TreeNode or ListViewItem).

* *TabControl必须至少一个TabPage在其TabPages集合。** The TabControl must have at least one TabPage in its TabPages collection.

适用于

另请参阅