日期:2014-05-18 浏览次数:20984 次
private void Form1_Load(object sender, EventArgs e) { for(int i=1;i<=70;i++) this.Controls["button" + i].Click += new EventHandler(button_Click); } void button_Click(object sender, EventArgs e) { ShowKT(); }
------解决方案--------------------
楼主可以把按钮都放在一个Panel里,当然可以不这样做,我的代码如下:
private void Form1_Load(object sender, EventArgs e) { foreach (Control c in this.panel1.Controls) { if (c is Button) { c.Click += new EventHandler(c_Click); } } } /// <summary> /// 按钮实现方法 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void c_Click(object sender, EventArgs e) { }