Button.PerformClick メソッドとは何? わかりやすく解説 Weblio辞書 (original) (raw)
他のボタンの Click イベントが発生したときに、一回おきに Button の Click イベントを生成するコード例を次に示します。このコードは、2 つの Button コントロールがフォーム上でインスタンス化され、myVar という名前のメンバ変数がクラス内の 32 ビット符号付き整数として宣言されていることを前提にしています。
Private 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
private 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;
}
private:
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++;
}
private 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;
} //button1_Click
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;
}