Button.PerformClick メソッドとは何? わかりやすく解説 Weblio辞書 (original) (raw)

他のボタンClick イベント発生したときに、一回おきに ButtonClick イベント生成するコード例次に示します。このコードは、2 つButton コントロールフォーム上でインスタンス化され、myVar という名前のメンバ変数クラス内の 32 ビット符号付き整数として宣言されていることを前提にしています。

Visual Basic

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

C#

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; }

C++

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++; }

J#

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

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; }