0

I have a form with four tabs total, but only two of which accept input. The tab control is called tabControl1 and the two tabs that accept input are tabAddUser and tabDisclaimer. On the Ass User tab I want the initial focus to go to txtFirstName and on the Disclaimer tab I want it to be set to rtbDisclaimer. I've searched around with no luck finding quite what I was looking for. This is the closest I found, but the focus wasn't set to anything when I ran it and selected the Add User tab.

private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
    if (tabControl1.SelectedTab == tabAddUser)
    {
        txtFirstName.Focus();
    }
}
  • The focus *has* to be set to something, and it cannot be set to two things at once. The code you have seems reasonable. What got selected instead? – Cody Gray - on strike Mar 09 '16 at 17:00
  • There's no focus set to anything. I can click the different tabs, but the type pointer isn't automatically positioned anywhere. The textbox on that tab is also in a groupbox if that makes any difference. So if I hit tab I think it starts off on the groupbox as a whole and then goes to the first button outside of the groupbox. However on the disclaimer tab there's no groupbox. Just a rtb. –  Mar 09 '16 at 17:01
  • That doesn't make much sense. As I said, *something* has to have the focus. And that something has to be a focusable control. Groupboxes can never take the focus. Do check your tab order to make sure that it is sensible. Give the control you want to be initially focused the lowest index. Also try using `Select` instead of `Focus`. I believe `Focus` *should* work there, since the control is visible, but I can't remember exactly when the event gets fired (before or after the tab change occurs). – Cody Gray - on strike Mar 09 '16 at 17:14
  • Using select fixed it. Thanks. :) –  Mar 09 '16 at 17:20

0 Answers0