Control.Click 事件

定義

當按下控制器時會發生。

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 就會被觸發。 例如,如果你有事件處理器來處理 ClickDoubleClickForm 事件Click,當雙擊表單並呼叫兩個方法時,和DoubleClick事件就會被觸發。 若雙擊某個控制項且該控制項不支援該 DoubleClick 事件, Click 事件可能會被重複提起。

你必須設定 StandardClickControlStyles 值 to true 才能提升此事件。

Note

除非集合中至少有一個事件,否則以下事件不會被提出TabControlTabPage、、TabControl.TabPagesClickDoubleClickMouseDownMouseUpMouseHoverMouseEnterMouseLeaveMouseMove 如果集合中至少有一個 TabPage ,且使用者與分頁控制項的標頭(名稱出現的地方 TabPage )互動,就會 TabControl 觸發相應事件。 然而,如果使用者互動發生在分頁頁面的客戶端區域,就會 TabPage 觸發相應的事件。

如需處理事件的詳細資訊,請參閱 處理和引發事件

繼承者備註

從標準Windows Forms控制項繼承並將StandardClickStandardDoubleClickControlStyles 的值改為 true,若控制不支援 ClickDoubleClick 事件,則可能產生意外行為或完全無效。

下表列出Windows Forms控制項,以及根據指定滑鼠動作會引發的事件(ClickDoubleClick)。

管理 左鍵點擊 左鍵雙擊 右鍵點擊 右鍵雙擊 中鍵點擊 中鍵雙擊 XButton1 滑鼠點擊 XButton1 滑鼠 Double-Click XButton2 滑鼠點擊 XButton2 滑鼠 Double-Click
MonthCalendarDateTimePickerHScrollBarVScrollBar none none none none none none none none none none
ButtonCheckBoxRichTextBoxRadioButton 按一下 喀嚓,喀嚓 none none none none none none none none
ListBoxCheckedListBoxComboBox 按一下 點擊,雙擊 none none none none none none none none
TextBoxDomainUpDownNumericUpDown 按一下 點擊,雙擊 none none none none none none none none
* TreeView, * ListView 按一下 點擊,雙擊 按一下 點擊,雙擊 none none none none none none
ProgressBarTrackBar 按一下 喀嚓,喀嚓 按一下 喀嚓,喀嚓 按一下 喀嚓,喀嚓 按一下 喀嚓,喀嚓 按一下 喀嚓,喀嚓
FormDataGridLabelLinkLabelPanelGroupBoxPictureBox, ** SplitterStatusBarToolBarTabPageTabControl 按一下 點擊,雙擊 按一下 點擊,雙擊 按一下 點擊,雙擊 按一下 點擊,雙擊 按一下 點擊,雙擊

* 滑鼠指標必須位於子物件(TreeNodeListViewItem)。

** 他們的TabControl收藏中至少必須有一張TabPageTabPages

適用於

另請參閱