greatmajestics
greatmajestics

Reputation: 1093

how to change TextBox Focus in c#?

I am working in Windows Form framework of c# , i have developed a form consisting of two textboxes (name and address). Problem is when i start my application focus is on address rather then name, how can i change this settings? Thank you in advance.

Upvotes: 0

Views: 10778

Answers (5)

Guillaume Lafrance
Guillaume Lafrance

Reputation: 67

I personally use the ActiveControl property. Never failed me as of today.

ActiveControl = Address;

Upvotes: 0

lorenz albert
lorenz albert

Reputation: 1459

Hope this ll help you. Select will change for user input

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        textBoxName.Select();
        textBoxName.Focus();

    }
}

Upvotes: 4

Buzz
Buzz

Reputation: 6320

set focus on the text box like this

txtbxname.Focus();

Upvotes: 1

Amal Dev
Amal Dev

Reputation: 1978

Just set the Tab Index property of the textbox as 0. Otherwise you can set call the focus method on load event

Upvotes: 1

Habib
Habib

Reputation: 223187

In Form_Load event call:

yourTextBox.Focus();

You may look at Control.Focus() on msdn

You may also look at this article to Set the Tab order if you don't want to use Focus()

Upvotes: 1

Related Questions