tags:

views:

44

answers:

1

I have TextBox placed on a UserControl on a Panel which is placed in a Form. But couldn't set focus by this code,

mytxtBox.Focus();

ActiveControl = mytxtBox;

mytxtBox.Select();

Why its not working? How to set focus here?

+1  A: 

If you wish to call this code from the Form you need to change the textbox modifiers property to public.

Then from the form you can call

userControl11.textBox1.Focus();
astander
Also, the reason his code isn't working is it looks like he's doing it from the user control, not the form, so the form ultimately is in control here and has to set focus.
GalacticCowboy