Control.Click 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
单击控件时发生。
public:
event EventHandler ^ Click;
public event EventHandler Click;
public event EventHandler? Click;
member this.Click : EventHandler
Public Custom Event Click As EventHandler
事件类型
示例
下面的代码示例演示 Click 事件处理程序中的事件。
// 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 其事件处理程序,因此它只指示单击已发生。 如果需要更具体的鼠标信息(按钮、单击次数、滚轮旋转或位置),请使用 MouseClick 事件。 但是, MouseClick 如果单击是由鼠标以外的操作(例如按 Enter 键)引起的,则不会引发该事件。
双击由用户的操作系统的鼠标设置决定。 用户可以设置鼠标按钮单击之间的时间,该按钮应被视为双击,而不是两次单击。 Click每次双击控件时都会引发该事件。 例如,如果你有事件的ClickDoubleClickFormClick事件处理程序,则当双击窗体并调用这两种方法时,将引发和DoubleClick事件。 如果双击某个控件并且该控件不支持该 DoubleClick 事件, Click 则可能会引发该事件两次。
必须设置StandardClick要引发此事件的值ControlStylestrue。
注释
除非集合TabControl中至少有一个:、、TabPage、TabControl.TabPages、ClickDoubleClick、、 MouseDown和MouseUp中MouseHover至少有一个MouseEnter,否则不会为MouseLeave类引发以下MouseMove事件。 如果集合中至少有一个 TabPage ,并且用户与选项卡控件的标头(其中 TabPage 显示名称)交互,则会 TabControl 引发相应的事件。 但是,如果用户交互位于选项卡页的工作区内,则会 TabPage 引发相应的事件。
有关处理事件的详细信息,请参阅 处理和引发事件。
继承者的注释
从标准Windows 窗体控件继承并将 StandardClick 或 StandardDoubleClick 值ControlStyles更改为 true可能会导致意外行为,或者如果控件不支持 Click 或 DoubleClick 事件,则根本不起作用。
下表列出了Windows 窗体控件以及为响应指定的鼠标操作而引发的事件(Click或 DoubleClick)。
| 控件 | 鼠标左键单击 | 鼠标左键双击 | 右键单击 | 鼠标右键双击 | 鼠标中键单击 | 鼠标中间双击 | XButton1 鼠标单击 | XButton1 鼠标 Double-Click | XButton2 鼠标单击 | XButton2 鼠标 Double-Click |
|---|---|---|---|---|---|---|---|---|---|---|
| MonthCalendar、DateTimePicker、HScrollBar、VScrollBar | 没有 | 没有 | 没有 | 没有 | 没有 | 没有 | 没有 | 没有 | 没有 | 没有 |
| Button、CheckBox、RichTextBox、RadioButton | 单击 | 单击,单击 | 没有 | 没有 | 没有 | 没有 | 没有 | 没有 | 没有 | 没有 |
| ListBox、CheckedListBox、ComboBox | 单击 | 单击,DoubleClick | 没有 | 没有 | 没有 | 没有 | 没有 | 没有 | 没有 | 没有 |
| TextBox、DomainUpDown、NumericUpDown | 单击 | 单击,DoubleClick | 没有 | 没有 | 没有 | 没有 | 没有 | 没有 | 没有 | 没有 |
| * TreeView, * ListView | 单击 | 单击,DoubleClick | 单击 | 单击,DoubleClick | 没有 | 没有 | 没有 | 没有 | 没有 | 没有 |
| ProgressBar、TrackBar | 单击 | 单击,单击 | 单击 | 单击,单击 | 单击 | 单击,单击 | 单击 | 单击,单击 | 单击 | 单击,单击 |
| Form、、DataGrid、LabelLinkLabel、Panel、GroupBox、PictureBox、 SplitterStatusBarToolBarTabPage**TabControl | 单击 | 单击,DoubleClick | 单击 | 单击,DoubleClick | 单击 | 单击,DoubleClick | 单击 | 单击,DoubleClick | 单击 | 单击,DoubleClick |
* 鼠标指针必须位于子对象上(TreeNode 或 ListViewItem)。
TabControl** 集合TabPage中必须至少有一个TabPages。