How to programmatically select the .NET CF TabControl tab?

Using 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; } 

In the .NET Framework, Compact TabControl does not have the SelectedTab property like its counterpart, the .NET Framework. So how can I select a tab programmatically?

+7
c # compact-framework tabcontrol
source share
5 answers

TabControl.SelectedIndex

+21
source share

I have programmed this code. When you click on tabPage1, the program will close:

 private void tabControl1_MouseClick(object sender, MouseEventArgs e) { if (tabControl1.SelectedTab == tabPage1) { MessageBox.Show("Logout!"); Application.Exit(); } } 
0
source share

in .Net 4 can use

 if (tabControl1.Controls[5] == tabControl1.SelectedTab) MessageBox.Show("Tab 5 Is Selected"); 

OR

 if ( tabpage5 == tabControl1.SelectedTab) MessageBox.Show("Tab 5 Is Selected"); 
0
source share

I found that when choosing TabControl it does not display correctly. After choosing TabControl, it seems useful to update it. So where the TabControl is called TabForm and has several tabs, it could be:

  Me.TabForm.SelectedIndex = 0 Me.TabPg0.Refresh 'Where TabPg0 is the name of the Tab at Index 0 
0
source share

WPF code, try the following:

 if (tabControl1.SelectedValue == tabPage1) tabControl1.SelectedValue = tabPage2; else tabControl1.SelectedValue = tabPage1; 
-2
source share

All Articles