hi,
I am having a user control and windows application form. In user control I have 16 buttons. and In form, I am having one textbox and this user control. I want to give focus to all these buttons in the form at runtime so that if I press on these buttons , the button text should enter in the textbox. how I need to do this.
Thanx in advance.
Loading

Ben25 reputationPosted Sep 11, 2009, 5:43 AM EDT
If i understand what you're trying to do, you should simply handle the click event of the buttons.
Create a public method in your form with a string as parameters.
And call that method in the click event handler.
FORM
---
public void ChangeTextboxText(String str)
{
this.textbox.Text = str;
}
USERCONTROL
---
foreach (Control ctrl in this.Controls)
{
if (ctrl.getType() == new Button().getType())
{
((Button)ctrl).Click += +=new EventHandler(button_Click);
}
}
void button_Click(object sender, EventArgs e)
{
((Form)this.Parent).ChangeTextboxText(((Button)sender).Text);
}
srinath133 reputationPosted Sep 11, 2009, 10:16 PM EDT
Actually, I created a user control which consists of panel and inside a panel I have buttons. I gave added this user control as a reference to windows application. In form I added this usercontrol and one textbox of form. I gave button press event in user control and appropriate function of diplaying the text in textbox in form. My problem is at runtime, When I press a button on the keyboard, the action is not entering to the usercontrol code and when I click using mouse on the button i.e by giving the focus to the button only the execution is entering into the usercontrol code. Please, give me the solution..