ボタンの Click イベントを生成します。
Public Overridable Sub PerformClick() Implements _
IButtonControl.PerformClick
[C#]
public virtual void PerformClick();
[C++]
public: virtual void PerformClick();
[JScript]
public function PerformClick();
実装
解説
このメソッドを呼び出して Click イベントを発生させることができます。
使用例
ほかのボタンの Click イベントが交互に切り替わるときに Button の Click イベントを生成する例を次に示します。このコードは、2 つの Button コントロールがフォーム上でインスタンス化され、 myVar
という名前のメンバ変数がクラス内の 32 ビット符号付き整数として宣言されていることを前提にしています。
Protected Sub button1_Click(sender As Object, e As EventArgs)
' If myVar is an even number, click Button2.
If myVar Mod 2 = 0 Then
button2.PerformClick()
' Display the status of Button2's Click event.
MessageBox.Show("button2 was clicked ")
Else
' Display the status of Button2's Click event.
MessageBox.Show("button2 was NOT clicked")
End If
' Increment myVar.
myVar = myVar + 1
End Sub 'button1_Click
[C#]
protected void button1_Click (Object sender,
EventArgs e)
{
// If myVar is an even number, click Button2.
if(myVar %2 == 0)
{
button2.PerformClick();
// Display the status of Button2's Click event.
MessageBox.Show("button2 was clicked ");
}
else
{
// Display the status of Button2's Click event.
MessageBox.Show("button2 was NOT clicked");
}
// Increment myVar.
myVar = myVar + 1;
}
[C++]
protected:
void button1_Click (Object* /*sender*/, EventArgs* /*e*/)
{
// If myVar is an even number, click Button2.
if(myVar %2 == 0)
{
button2->PerformClick();
// Display the status of Button2's Click event.
MessageBox::Show(S"button2 was clicked ");
}
else
{
// Display the status of Button2's Click event.
MessageBox::Show(S"button2 was NOT clicked");
}
// Increment myVar.
myVar++;
}
[JScript]
protected function button1_Click (sender : Object, e : EventArgs)
{
// If myVar is an even number, click Button2.
if(myVar %2 == 0)
{
button2.PerformClick();
// Display the status of Button2's Click event.
MessageBox.Show("button2 was clicked ");
}
else
{
// Display the status of Button2's Click event.
MessageBox.Show("button2 was NOT clicked");
}
// Increment myVar.
myVar = myVar + 1;
}
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ