Reputation: 373
I have create a tabcontrol in Silverlight 4 with four tabs, is possible open a tab with button?
this cose is only windows forms
tabControl1.SelectedTab = tabPage4;
Upvotes: 0
Views: 16823
Reputation: 41
Source: Youtube C# Tabpage Select with button, 3 way.
private void btnPage1_Click(object sender, EventArgs e)
{
Button button = sender as Button ;
// method 1
if(button==button1)
tabControl1.SelectedIndex = 0;
else if(button==button2)
tabControl1.SelectedIndex = 1;
else // if(button==button3)
tabControl1.SelectedIndex = 2;
// method 2
if(button==button1)
tabControl1.SelectedTab = tabControl1.TabPages["tabPage1"];
else if(button==button2)
tabControl1.SelectedTab = tabControl1.TabPages["tabPage2"];
else // if(button==button3)
tabControl1.SelectedTab = tabControl1.TabPages["tabPage3"];
// method 3
// button Name : btnPage1, btnPage2, btnPage3
// tabPage Name : tabPage1, tabPage2, tabPage3
string tabName = button.Name.Replace("btn", "tab") ;
tabControl1.SelectedTab = tabControl1.TabPages[tabName] ;
}
Upvotes: 0
Reputation: 10509
Use TabControl.SelectedIndex
property to change the selected tab from code.
For example, when you want to select the third tab:
tabControlName.SelectedIndex = 2;
Upvotes: 5
Reputation: 44605
If you are using the: TabControl Class
surely you can use one of these two properties:
SelectedIndex - Gets or sets the index of the currently selected TabItem
SelectedItem - Gets or sets the currently selected TabItem.
Upvotes: 0