| 发表于:2007-08-29 15:10:002楼 得分:20 |
在form1.designer.cs中有下面两段代码 this.button1.location = new system.drawing.point(75, 59); this.button1.name = "button1 "; this.button1.size = new system.drawing.size(75, 23); this.button1.tabindex = 0; this.button1.text = "button1 "; this.button1.usevisualstylebackcolor = true; this.button1.click += new system.eventhandler(this.button1_click_1); // // button2 // this.button2.location = new system.drawing.point(75, 118); this.button2.name = "button2 "; this.button2.size = new system.drawing.size(75, 23); this.button2.tabindex = 2; this.button2.text = "button2 "; this.button2.usevisualstylebackcolor = true; this.button2.click += new system.eventhandler(this.button2_click); 你只要把其中的 this.button1.click += new system.eventhandler(this.button1_click_1); this.button2.click += new system.eventhandler(this.button2_click); 改成 this.button1.click += new system.eventhandler(this.button1_click_1); this.button2.click += new system.eventhandler(this.button1_click); 然后在 private void button1_click_1(object sender, eventargs e) { if(((button)sender).text== "button1 ") // if(((button)sender).text== "button2 ") // } 就可以了 原理就是将所有按钮的委托中执行的函数都指定为同一个,然后在这个函数中判断是点击了哪个按钮,执行相应的操作 | | |
|