如何使用C#单击按钮在文本框中显示按钮的文本 [英] How to display the text of a button in text box by clicking the button using C#

查看:1269
本文介绍了如何使用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;


这篇关于如何使用C#单击按钮在文本框中显示按钮的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆