Working With Tab Control In Windows Forms Using Visual Studio 2017


In this article, I am going to explain how to work with tab control in WindowsForms using Visual Studio 2017. Tab control presents a tabbed layout in the user-interface. The .NET Framework provides a versatile and easy-to-use control. In this article, I am going to explain how to add the control, change its pages, and manipulate it in C#.


Tab control allows you to split your interface up into different areas, each accessible by clicking on the tab header, usually positioned at the top of the control. Tab controls are more commonly used in Windows applications and even within Windows' own interface, like the properties dialog for files/folders, etc.
STEP 1 - Start the Project
Open Visual Studio 2017----> Windows Form Application---> name it as Tab Control.
Windows Forms
STEP 2 - Drag and Drop
By default, the form designer page will be loaded and you need to drag and drop tab control from the toolbox onto the form in Visual Studio 2017. 
Windows Forms 


Right-click on the tab control and select properties. You can see the tab page called "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.
Windows Forms 
Drag and drop the button control on both tab pages from the toolbox onto the form in Visual Studio 2017.
Windows Forms 
Follow the code given below in the screenshot for the button click event in both tab pages.
  1. private void button1_Click(object sender, EventArgs e) {  
  2.  MessageBox.Show("Button from view 1 has been clicked!!!");  
  3. }  
  4. private void button2_Click(object sender, EventArgs e) {  
  5.  MessageBox.Show("Button from view 2 has been clicked!!!");  
  6. }   
 Windows Forms
Compile and run the code. The following output is obtained as given below in the screenshot. Whenever the button in the tab pages is clicked the following message box with the text will appear.
Windows Forms
Windows Forms 
STEP 5 - Additional Setting
Adjusting the Tab pages 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 to add ten pages. If it is simple, you might need only two. 
Windows Forms
Windows Forms 
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. I hope this article is interesting. If you have any error or problem with the code feel free to comment below.