tab control+C#+VS 2008+Window application

Posted on 2011-10-05
Last Modified: 2012-05-12
i have a tab control involves 2 tabpages as follow;


The Tab1 inolves a button.
I want in case  the user click on the button directly we go to the Tab2.

how i can do it.
Question by:MKItani
    LVL 74

    Assisted Solution

    by:käµfm³d 👽
    It should be something along the lines of:

    private void button1_Click(object sender, EventArgs e)
        this.tabControl1.SelectedTab = this.tabControl1.TabPages[1];

    Open in new window

    where button1 is the button on the first tab page.
    LVL 13

    Accepted Solution

    Use something like this:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    namespace WindowsFormsApplication2
        public partial class Form1 : Form
            private TabControl tabControl1;
            private TabPage tab1;
            private Button button1;
            private TabPage tab2;
            public Form1()
            private void InitializeComponent()
                this.tabControl1 = new System.Windows.Forms.TabControl();
                this.tab1 = new System.Windows.Forms.TabPage();
                this.tab2 = new System.Windows.Forms.TabPage();
                this.button1 = new System.Windows.Forms.Button();
                // tabControl1
                this.tabControl1.Location = new System.Drawing.Point(13, 13);
                this.tabControl1.Name = "tabControl1";
                this.tabControl1.SelectedIndex = 0;
                this.tabControl1.Size = new System.Drawing.Size(259, 237);
                this.tabControl1.TabIndex = 0;
                // tab1
                this.tab1.Location = new System.Drawing.Point(4, 22);
                this.tab1.Name = "tab1";
                this.tab1.Padding = new System.Windows.Forms.Padding(3);
                this.tab1.Size = new System.Drawing.Size(251, 211);
                this.tab1.TabIndex = 0;
                this.tab1.Text = "tab1";
                this.tab1.UseVisualStyleBackColor = true;
                // tab2
                this.tab2.Location = new System.Drawing.Point(4, 22);
                this.tab2.Name = "tab2";
                this.tab2.Padding = new System.Windows.Forms.Padding(3);
                this.tab2.Size = new System.Drawing.Size(251, 211);
                this.tab2.TabIndex = 1;
                this.tab2.Text = "tab2";
                this.tab2.UseVisualStyleBackColor = true;
                // button1
                this.button1.Location = new System.Drawing.Point(60, 62);
                this.button1.Name = "button1";
                this.button1.Size = new System.Drawing.Size(75, 23);
                this.button1.TabIndex = 0;
                this.button1.Text = "button1";
                this.button1.UseVisualStyleBackColor = true;
                this.button1.Click += new System.EventHandler(this.button1_Click);
                // Form1
                this.ClientSize = new System.Drawing.Size(284, 262);
                this.Name = "Form1";
            private void button1_Click(object sender, EventArgs e)
                tabControl1.SelectedTab = tab2;

    Open in new window


    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Suggested Solutions

    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now