Problem solve Get help with specific problems with your technologies, process and projects.

How do I set focus at form load in C#?

I tried the code for setting focus on a textbox with FORM1_LOAD and ActiveControl. I received the following error:

(101): 'RatingsEngine.RatingMediaInstance' does not contain a definition for 'ActiveControl'

Can you please guide me on how to go about setting focus at form load in C#? Thanks in advance for your help.
There are two ways of doing this:

  1. In the Form.Load event handler, write: this.ActiveControl = txtInput;
  2. In the Form.Activate event handler, write: txtInput.Focus();

Dig Deeper on C# programming language

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.