Topic: TabControl Control

Table of Content

  • Introduction
  • Working
  • Code
  • Explanation of code

Introduction: This article will give you basic idea about how to create tabbed windows in visual studio. TabControl presents a tabbed layout in user interface. This enables to specify more information in the same space on a Form and group display data logically. A TabControl contains tab pages, which are represented by TabPage objects that you add through the TabPages property. The user can change the current TabPage by clicking one of the in controls.

Working: 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.

Capture

Right-click on the TabControl and select Properties. This will present you with the Properties dialog, which you can use to adjust many important visual settings and also the TabPages themselves.

Capture1

Adjusting the TabPages in the TabControl is important as this mechanism allows you to add a variable number of pages to your tab control. You can see the TabPage Collection Editor. If you need 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.

Capture2

Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TabControl_Control
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

//event handler for Hello! Radio button
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
label1.Text = “Hello !”;
}

//event handler for GoodBye! radio button
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
label1.Text = “GoodBye !”;
}

//event handler for deepPink radio button
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
label1.ForeColor = Color.DeepPink;
}

//event handler for red radio button
private void radioButton4_CheckedChanged(object sender, EventArgs e)
{
label1.ForeColor = Color.Red;
}

//event handler for green radio button
private void radioButton5_CheckedChanged(object sender, EventArgs e)
{
label1.ForeColor = Color.Green;
}

//event handler for 12 point radiobutton
private void radioButton6_CheckedChanged(object sender, EventArgs e)
{
label1.Font = new Font(label1.Font.Name, 12);
}

//event handler for 16 point radiobutton
private void radioButton7_CheckedChanged(object sender, EventArgs e)
{
label1.Font = new Font(label1.Font.Name, 16);
}

//event handler for 20 point radiobutton
private void radioButton8_CheckedChanged(object sender, EventArgs e)
{
label1.Font = new Font(label1.Font.Name, 20);
}
}
}

a)      Capture3

 

b)     4

c)     5

d)     6

Explanation of code: The message tabPage contains two radio buttons for the messges Hello ! (radioButton1) and GoodBye ! (radioButton2). The two radio buttons determine the text on label1.This tabPage is diplayed in Figure a. The color tabPage contains three radio buttons for the color Deep Pink (radiobutton3) , red (radiobutton4) , green (radiobutton5). This tabPage is displayed in Figure b. The size tabPage has three radio buttons, corresponding to font sizes 12 (radioButton6) , 16 (radioButton7) , 20 (radioButton8) which change the font size of label1. This tabPage is shown in figure c. The about tabPage contains a Rich Textbox describing the purpose of TabControls. this tabPage is diplayed in figure d.