写了一个函数 可以让点击button1或button2时运行同一个函数
private void A(object sender,EventArgs e)
{
if((Button)(sender)==button1)
{
label1.Text = "我是按钮1";
}
else
{
label1.Text = "我是按钮2";
}
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(44, 58);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(127, 42);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.A);//这是自己添加的
//
// button2
//
this.button2.Location = new System.Drawing.Point(295, 60);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(128, 39);
this.button2.TabIndex = 1;
this.button2.Text = "button2";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.A);//这是自己添加的