本文整理汇总了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.");
}
}