Button.PerformClick 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
為 Click 按鈕產生事件。
public:
virtual void PerformClick();
public void PerformClick();
abstract member PerformClick : unit -> unit
override this.PerformClick : unit -> unit
Public Sub PerformClick ()
實作
範例
以下程式碼範例會在Click另一個按鈕的交替Button事件中產生 a Click 事件。 此程式碼假設表單上實例化了兩個 Button 控制項,且在類別中宣告了一個 32 位元有符號的成員變數 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++;
}
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 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
備註
此方法可被呼叫以提升事件。Click