Code:
tabControlName.SelectedIndex = theIndexOfTheTabPage; //switch to the tab page
tabControl1.TabPages[theIndexOfTheTabPage].Controls.Find("textBoxName", true)[0].Select(); //find the TextBox and select it
The first line changes to the desired tab page by changing the SelectedIndex
property of the tabControl
. The second Line searches for the TextBox
using the Find(string name, bool searchAllChildren)
method. Then the TextBox
is focused by using the Select()
method.
To click a Button inside a tab use this code:
tabControlName.SelectedIndex = theIndexOfTheTabPage; //switch to the tab page
Button b = tabControlName.TabPages[theIndexOfTheTabPage].Controls.Find("buttonName", true)[0] as Button;
b.PerformClick();
First get the Button
the same way as the TextBox
. Then use PerformClick()
to click the Button