如何使用C#单击按钮在文本框中显示按钮的文本
问题描述:
你好b $ b
我有一个小问题。
我有28个按钮。
如果我点击这28个按钮中的任何一个,我想将按钮文本添加到文本框中。
我可以做到通过做
Hi
I having a small problem.
I am having 28 buttons.
If I click any of these 28 buttons I want to add the button text to the text box.
I can do it by doing
txtUser.Text=btn15.Text
但是不要想手动编写所有代码,有没有办法减少代码
But dont want to write all the codes manually so is there any way to reduce the code
答
看到:http://stackoverflow.com/questions/6315936/c-sharp-how-to-use-一键式事件处理程序 - 多个按钮 [ ^ ]
尝试使用按钮单击事件,发件人参数转换为按钮然后将按钮文本设置为适当的文本Box
Try With using Buttons Click event, Sender parameter Convert to Button.Then Set Button text to Appropriate TextBox
Button b3 = (Button)sender;
txt.Text=b3.Text;