using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace day13
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_Click(object sender, EventArgs e)
{
Button btn = (Button)sender; //实例化按钮,从而实现获得当前按钮的值
this.txtShow.Text = btn.Text;
}
private void Form1_Load(object sender, EventArgs e)
{
//通过以下代码,将按钮控件的Click事件绑定到btn_Click上面,从而实现动态注册按钮事件
btn1.Click+=new EventHandler(btn_Click);
btn2.Click+=new EventHandler(btn_Click);
btn3.Click+=new EventHandler(btn_Click);
btn4.Click+=new EventHandler(btn_Click);
btn5.Click+=new EventHandler(btn_Click);
}
}
}