激活 TabControl 的 TabPage

中使用 TabControl。NET 应用程序。默认情况下,TabControl 的第一个选项卡页显示在表单加载中。我想在表单加载中显示其他选项卡页。如何以编程方式显示不同的选项卡页?

177751 次浏览
tabControl1.SelectedTab = MyTab;

or

tabControl1.SelectedTab = tabControl1.TabPages["tabName"];

Where tabName is the Name of the tab you want to activate (tabName is NOT the text display).

There are two properties in a TabControl control that manages which tab page is selected.

SelectedIndex which offer the possibility to select it by index (an integer starting from 0 to the number of tabs you have minus one).

SelectedTab which offer the possibility to selected the tab object itself to select.

Setting either of these property will change the currently displayed tab.

Alternatively you can also use the Select method. It comes in three flavour, one where you pass the index of the tab, another the TabPage object itself and the last one a string representing the tab's name.

You can use the method SelectTab.

There are 3 versions:

public void SelectTab(int index);
public void SelectTab(string tabPageName);
public void SelectTab(TabPage tabPage);

For Windows Smart device (compact frame work ) (MC75-Motorola devices)

     mytabControl.SelectedIndex = 1

Use SelectTab like this:

TabPage t = tabControl1.TabPages[2];
tabControl1.SelectTab(t); //go to tab

Use SelectedTab like this:

TabPage t = tabControl1.TabPages[2];
tabControl1.SelectedTab = t; //go to tab