user2856563
user2856563

Reputation: 29

How can I view a different tab using a button?

In visual studio I have created a windows form with a tab menu.Can I use a button to switch between the tabs and how would I do that?

Upvotes: 0

Views: 76

Answers (2)

jhyap
jhyap

Reputation: 3837

    private void button1_Click(object sender, EventArgs e)
    {
        tabControl1.SelectedIndex++;
    }

Set a conditional statement and do the tabControl1.SelectedIndex-- to switch back to previous tab.

OR use two buttons

    private void button2_Click(object sender, EventArgs e)
    {
        tabControl1.SelectedIndex--;
    }

Upvotes: 0

NoChance
NoChance

Reputation: 5752

Assuming you are using Windows Forms, here is an example of switching to 2nd tab page in a tab control named tabcontrol1. Remember that the first tab page has an index of zero. Of course, you should have a tab control with 2 pages to use this code.

this.tabControl1.SelectedTab = this.tabControl1.TabPages[1];

Upvotes: 1

Related Questions