Click here to Skip to main content
15,889,863 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
txtUser.Text=btn15.Text


But dont want to write all the codes manually so is there any way to reduce the code
Posted
Comments
[no name] 9-Jun-14 9:10am    
The sender parameter is the button that was clicked, use that.
KUMAR619 9-Jun-14 9:25am    
Control ctrl = (Control)sender;
txt.Text=ctrl.Text

 
Share this answer
 
Comments
KUMAR619 9-Jun-14 9:25am    
Control ctrl = (Control)sender;
txtText.text=ctrl.Text;
Try With using Buttons Click event, Sender parameter Convert to Button.Then Set Button text to Appropriate TextBox

C#
Button b3 = (Button)sender;
txt.Text=b3.Text;
 
Share this answer
 
v2
Comments
KUMAR619 9-Jun-14 9:24am    
Control ctrl = (Control)sender;
txt.Text=ctrl.Text

Because Once I do This I can write one event for all the button.
I got it Thanks for your help
Nirav Prabtani 9-Jun-14 9:25am    
my 5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900