Hi, i'm trying to focus the cursor on a textbox inside one of my tab controls (3 tabs) but my method doesn't seem to work...Any ideas?
Here is my code:

private void Maintenance_Load(object sender, EventArgs e)
        {
            tabControl1.Focus();
            tabControl1.SelectedIndex = 0;
            txt_CLName.Focus();
        }

Hi,

I ran the same code and it focuses fine.
You dont need to call

tabControl1.Focus();

since you then move focus to the textbox.
When you set the SelectedIndex for the tabControl are you selecting the tab page which contains the textbox?

The other thing to do is check that nothing is calling focus away from the textbox after you set focus to it.

Hello, phoenix_dwarf.

While playing with your code found interesting thingy: it works fine on every tab .. except the 1st one. Anyway, while trying to explain such behaviour, found this:

Note:
Focus is a low-level method intended primarily for custom control authors. Instead, application programmers should use the Select method or the ActiveControl property for child controls, or the Activate method for forms.

So, this should work fine:

tabControl1.SelectedIndex = 0;
txt_CLName.Select();
Comments
nice catch, i learnt something too here :p

Tnx Antenka...it works. I'm just puzzled by why my original code doesn't want to work...? l0olâ„¢ Ahw well, thnx again!

This question has already been answered. Start a new discussion instead.