Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I programmatically select a tab on a .NET CF TabControl?

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?

like image 994
raven Avatar asked May 08 '09 18:05

raven


People also ask

How do I select a tab?

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.

How do I select a Tabpage in Tabcontrol in VB net?

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.


2 Answers

TabControl.SelectedIndex

like image 180
Cheeso Avatar answered Sep 30 '22 06:09

Cheeso


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();
        }
    }
like image 21
rafał Avatar answered Sep 30 '22 06:09

rafał