With the .NET Framework 2.0/3.5 TabControl, I can programmatically select a tab using the SelectedTab property as shown in the code below:
//toggles between tabPage1 and tabPage2
private void button1_Click(object sender, EventArgs e)
{
if (tabControl1.SelectedTab == tabPage1)
tabControl1.SelectedTab = tabPage2;
else
tabControl1.SelectedTab = tabPage1;
}
The .NET Compact Framework TabControl doesn't have a SelectedTab property like its .NET Framework counterpart. So, how do I select a tab programmatically?
Hold down the Shift key to select multiple tabs in a row or Ctrl / ⌘ key to select tabs that aren't necessarily next to each other.
To select a tab page on the form, first click its tab, then click its body. In the top combo box of the Properties window, select the name of the desired property page. On the form, click the tab control. In the Properties window, click the TabPages field and click its ellipsis button.
TabControl.SelectedIndex
I programmed this code. When click on tabPage1, then the program will close:
private void tabControl1_MouseClick(object sender, MouseEventArgs e)
{
if (tabControl1.SelectedTab == tabPage1)
{
MessageBox.Show("Logout!");
Application.Exit();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With