Giving a TextBox the Focus when the form comes up

  • Thread starter Thread starter Randy
  • Start date Start date
R

Randy

Hello all,
I have a form with a text field (textBox1) on it.
Apparently, textBox1.Focus() doesn't work when the form is initializing. I
put this in the Constructor and also in the Load event for the form.
textBox1 still doesn't get the focus when the form comes up. How do you do
this?
Thanks
 
Form.Activated event works but the problem is that this transfers focus to
textbox every time form gets activated.

I know we can keep a flag variable to check it.

Is there any other straight forward way to do this.

Thanks
 
Randy said:
I have a form with a text field (textBox1) on it.
Apparently, textBox1.Focus() doesn't work when the form is initializing. I
put this in the Constructor and also in the Load event for the form.
textBox1 still doesn't get the focus when the form comes up. How do you do
this?

textBox1.Focus() should work as long as it is *after* InitializeComponent().
Form_Load() is a good place for this. Focus() won't work though if the
textbox has .Enabled=false or .Visible=false.

If you're still having trouble please post a minimal code sample that
illustrates the problem.

-- Alan
 
Thanks, I didn't have the tab order set...I put the text box as the first on
the tab order and it works like I expected...thanks again..
 
Back
Top