本文整理匯總了C#中System.Windows.Forms.Button.PerformClick方法的典型用法代碼示例。如果您正苦於以下問題:C# Button.PerformClick方法的具體用法?C# Button.PerformClick怎麽用?C# Button.PerformClick使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Windows.Forms.Button
的用法示例。
在下文中一共展示了Button.PerformClick方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: 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;
}
示例2: Button.PerformClick()
//引入命名空間
using System;
using System.Drawing;
using System.Windows.Forms;
public class ButtonEvent : Form
{
Button btn1;
Button btn2;
public ButtonEvent()
{
Size = new Size(200,100);
btn1 = new Button();
btn1.Parent = this;
btn1.Text = "Button1";
btn1.Location = new Point(10,10);
btn1.Click += new System.EventHandler(btn1_Click);
btn2 = new Button();
btn2.Parent = this;
btn2.Text = "Button2";
btn2.Location = new Point(100,10);
btn2.Click += new System.EventHandler(btn2_Click);
}
static void Main()
{
Application.Run(new ButtonEvent());
}
private void btn1_Click(object sender, EventArgs e)
{
MessageBox.Show("Button1 clicked.");
btn2.PerformClick();
}
private void btn2_Click(object sender, EventArgs e)
{
MessageBox.Show("Button2 clicked.");
}
}