TabControl

TabControl presents a tabbed layout in the user interface. The .NET Framework provides this versatile and easy-to-use control.
We add the control,
change its pages,
manipulate it in C# code,
and change its visual settings.

TabControl

Start

Steps

To begin, you will need to create a new Windows Forms application in Visual Studio. Then, you can add the TabControl by opening the Toolbox pane and double-clicking on the TabControl icon.

Next:Right-click on the TabControl and select Properties. This will present you with the Properties dialog.

Properties:You can use this dialog to adjust many important visual settings and also the TabPages themselves.

TabControl

TabPages

Adjusting the TabPages in the TabControl is important. This mechanism allows you to add a variable number of pages to your tab control. If your application is complex, you might need ten tab pages. If it is simple, you might only need two.

Tip:Please remember that users might get frustrated with complicated user interfaces.

TabControl

Above, you can see the TabPage Collection Editor. To add an additional tab, please click the Add button.
To remove a tab,
select it
and click Remove. You can change the background color of tabs, the font color, and many other things.

Tip:You should leave these alone unless your application's goal is to cause headaches.

Typically:It is smartest to use the default user interface colors for most applications.

Change tabs

Question

How can you manipulate the TabControl using the C# language? First, if you want to do something in code when the user interacts somehow with the TabControl, try clicking on the lightning bolt icon and finding the appropriate event.

Another thing you can do, as we see here, is programmatically change the selected tab. You can use this sort of code to restore a tab to the one that was open when the application last closed, or just to focus a specific one on startup.

C# program that uses SelectTab and SelectedIndex

using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
	public Form1()
	{
	    InitializeComponent();
	    // After initialize, select the second tab.
	    tabControl1.SelectTab("tabPage2");
	    // This is another way to select the second tab.
	    // ... You don't need both ways!
	    tabControl1.SelectedIndex = 1;
	}
    }
}

Appearance

Framework: NET

There are more tricks to the TabControl in the Windows Forms Framework. One nice feature the TabControl has is the ability to change the appearance of the tabs to buttons or flat buttons.

For some kinds of applications, particularly those where for some reason the tab metaphor is not effective, try using the Buttons or FlatButtons enumerated constants for the Appearance property. Here, we see the FlatButtons appearance.

TabControlProgramming tip

Please remember that the tabbed interface metaphor is thought to be very effective for many applications. In books such as Don't Make Me Think, by Steve Krug, this metaphor is shown to be much easier for users to interact with.

However:When you get too many tabs, the metaphor breaks down and it might be better to start using buttons for the appearance.

Summary

The C# programming language

The TabControl in the .NET Framework and Windows Forms is a powerful and easy-to-use layout control. It can help you keep clutter in the finished window to a minimum, while not restricting the range of options you offer.

And:TabControl can be manipulated programmatically in the C# code. Its default settings can be changed through Visual Studio.


C#: Windows