Search code examples
c#winformsfocussetfocus

How do I put focus on a TextBox when a form loads?


I have a TextBox in my C# program. I need focus to be on this TextBox when the program starts.

I tried this on Form_Load:

MyTextBox.Focus();

but it doesn't work.

How do I put focus on this when the form loads?


Solution

  • Set theActiveControl property of the form and you should be fine.

    this.ActiveControl = yourtextboxname;