Button.PerformClick 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
生成按钮的 Click 事件。
public:
virtual void PerformClick();
public void PerformClick ();
abstract member PerformClick : unit -> unit
override this.PerformClick : unit -> unit
Public Sub PerformClick ()
实现
示例
下面的代码示例在另一个按钮的Button交替Click事件上生成 一个 Click 事件。 此代码假定已在窗体上实例化了两 Button 个控件,并且名为 myVar
的成员变量已在 类中声明为 32 位有符号整数。
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 事件。