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 イベントを使用します。 ただし、クリックがマウス以外の操作 (Enter キーを押すなど) によって発生した場合、 MouseClick イベントは発生しません。
ダブルクリックは、ユーザーのオペレーティング システムのマウス設定によって決まります。 ユーザーは、2 回のクリックではなくダブルクリックと見なす必要があるマウス ボタンのクリック間隔を設定できます。 Click イベントは、コントロールがダブルクリックされるたびに発生します。 たとえば、ClickのDoubleClickイベントとFormイベントのイベント ハンドラーがある場合、フォームがダブルクリックされ、両方のメソッドが呼び出されると、ClickイベントとDoubleClick イベントが発生します。 コントロールがダブルクリックされ、そのコントロールが DoubleClick イベントをサポートしていない場合、 Click イベントが 2 回発生する可能性があります。
このイベントを発生させるには、StandardClickのControlStyles値をtrueに設定する必要があります。
Note
TabControl、TabPage、TabControl.TabPages、Click、DoubleClick、MouseDown、MouseUp、MouseHoverなど、MouseEnter コレクションに少なくとも 1 つのMouseLeaveがない限り、MouseMove クラスでは発生しません。 コレクションに少なくとも 1 つの 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 | none | none | none | none | none | none | none | none | none | none |
| Button、CheckBox、RichTextBox、RadioButton | クリックする対象 | クリックして、 | none | none | none | none | none | none | none | none |
| ListBox、CheckedListBox、ComboBox | クリックする対象 | Click、DoubleClick | none | none | none | none | none | none | none | none |
| TextBox、DomainUpDown、NumericUpDown | クリックする対象 | Click、DoubleClick | none | none | none | none | none | none | none | none |
| * TreeView, * ListView | クリックする対象 | Click、DoubleClick | クリックする対象 | Click、DoubleClick | none | none | none | none | none | none |
| ProgressBar、TrackBar | クリックする対象 | クリックして、 | クリックする対象 | クリックして、 | クリックする対象 | クリックして、 | クリックする対象 | クリックして、 | クリックする対象 | クリックして、 |
| Form、 DataGrid、 Label、 LinkLabel、 Panel、 GroupBox、 PictureBox、 Splitter、 StatusBar、 ToolBar、 TabPage、** TabControl | クリックする対象 | Click、DoubleClick | クリックする対象 | Click、DoubleClick | クリックする対象 | Click、DoubleClick | クリックする対象 | Click、DoubleClick | クリックする対象 | Click、DoubleClick |
* マウス ポインターは、子オブジェクト (TreeNode または ListViewItem) の上に置く必要があります。
** TabControlには、TabPage コレクションに少なくとも 1 つのTabPagesが必要です。