c#按键返回本按键Text

c#按键返回本按键Text

想用下面的代码完成:按下按键1,可以生成一个按键2,按键2的触发事件已经加载,希望通过按下新生成的按键2来显示本按键的Text。(后续希望通过这个小例子来得到更多的按键的Text)
JavaScript code?private void button1_Click(object sender, EventArgs e)                {                 Button button = new Button();                 button.Name = "button" + 2;                 button.Location = new Point(20, 20);                 button.Click += new EventHandler(button_Click);                 button.Text = "按键" + 2;                 this.Controls.Add(button);                 }      private void button_Click(object sender, EventArgs e)         {             MessageBox.Show("希望返回本次按下的按键的Text");           }

补充:主要是想通过新生成的按键实现一些功能,功能大部分相同,有些不一样,哪位大哥要是有这方面的例子,希望能附上,

MessageBox.Show(((Button)sender).Text);
不知道是不是你想要的

private void button1_Click(object sender, EventArgs e)         {             Button[] testButton = new Button[3];             for (int i = 0; i < testButton.Length; i++)             {                 testButton[i] = new Button();                 testButton[i].Name = "button" + i.ToString();                 testButton[i].Location = new Point(100 * i + 20, 20);                 testButton[i].Click += new EventHandler(button_Click);                 testButton[i].Text = "按键" + i.ToString();                 this.Controls.Add(testButton[i]);             }         }           private void button_Click(object sender, EventArgs e)         {             MessageBox.Show((((Button)sender).Text));         }

 private void button1_Click(object sender, EventArgs e)         {             Button[] testButton = new Button[3];             for (int i = 0; i < testButton.Length; i++)             {                 testButton[i] = new Button();                 testButton[i].Name = "button" + i.ToString();                 testButton[i].Location = new Point(100 * i + 20, 20);                 testButton[i].Click += new EventHandler(button_Click);                 testButton[i].Text = "按键" + i.ToString();                 this.Controls.Add(testButton[i]);             }         }           private void button_Click(object sender, EventArgs e)         {             MessageBox.Show((((Button)sender).Text));         }

Copyright © 2007-2012 www.chuibin.com 六维论文网 版权所有