[c#] how to put focus on TextBox when the form load?

5 Answers

check your tab order and make sure the textbox is set to zero


I have in my C# program textBox

I need that when the program start, the focus will be on the textBox

I try this on Form_Load:


but it wont work

In jquery set focus

$(function() {

or in Javascript you can do

window.onload = function() {

use form shown event and set


it's worked for me set tabindex to 0 this.yourtextbox.TabIndex = 0;

Textbox.Focus() "Tries" to set focus on the textbox element. In case of the element visibility is hidden for example, Focus() will not work. So make sure that your element is visible before calling Focus().

If you only want to set the focus the first time the form is shown, try handling the Form.Shown event and doing it there. Otherwise use Control.VisibleChanged.



c# c#   winforms