Working With Panel Control In Windows Forms Using Visual Studio 2017

INTRODUCTION

In this article, I am going to explain how to work with panel control in Windows Forms using Visual Studio 2017. Panel creates a group of Controls. This Control provides a simple frame for putting sub-controls inside. These sub-Controls include Buttons and Textboxes. It furthur provides an optional border and ways to change its visibility.

Sub Controls in Panel

The entire point of the panel is to provide a visual and logical grouping for controls. To add some controls to the panel, drag them to the inner part of the panel in Visual Studio

STEP 1 - Start the Project

Let's start the Project. Open Visual Studio 2017--->Start new Project--->Windows.Forms Application-->Name it as Panel Control

Windows Forms
 
STEP 2 - Drag and Drop Controls

By Default Form Designer Page will be loaded and in the Designer page, You need to create three pages with the Panel Control.
Page1:

In the form drag and drop Panel control from the toolbox onto the form in Visual Studio 2017. Inside the Panel Control, drag and drop other sub controls like Label ,TextBox, and Checkbox. Change the text of the controls as given below in the screenshot. 

Windows Forms 

Page 2

In the form, drag and drop panel control from toolbox onto the form in Visual Studio 2017. Insidde the Panel Control drag and drop other sub controls like Label,TextBox and PictureBox. Change the text of the controls as given below in the screenshot.

Windows Forms

Page 3

In the form drag and drop panel control from the toolbox onto the form in Visual Studio 2017. Inside the Panel Control drag and drop other sub controls like Label,TextBox and Picture Box. Change the text of the controls as given below in the screenshot.

Windows Forms

Drag and drop button control onto  the form from toolbox in Visual Studio 2017 and change the text of the button as previous and next.

Windows Forms 

STEP 3 - Coding

Follow the coding given below in the screenshot for panel cotrol in the windows  forms application.

Windows Forms

Windows Forms 
  1. private void button1_Click(object sender, EventArgs e)  
  2.        {  
  3.            if (index > 0)  
  4.                listpanel[--index].BringToFront();  
  5.        }  
  6.   
  7.        private void Form1_Load(object sender, EventArgs e)  
  8.        {  
  9.            listpanel.Add(panel1);  
  10.            listpanel.Add(panel2);  
  11.            listpanel.Add(panel3);  
  12.            listpanel[index].BringToFront();  
  13.        }  
  14.   
  15.        private void button2_Click(object sender, EventArgs e)  
  16.        {  
  17.            if (index < listpanel.Count - 1)  
  18.                listpanel[++index].BringToFront();  
  19.        }  
STEP 4 - Output

Compile and r unthe code and the following output wll be obtained as given below in the screenshot. As the next button is clicked pages  are navigated to the next page. When the previous button is clicked the pages are navigated to the previous pages.

The next button is clicked and page 2 is navigated to page 3

Windows Forms

Windows Forms 

Previous button is clicked and page 2  is navigated to page 1

Windows Forms

Windows Forms 

Summary

The Panel Control is a container or grouping mechanism in Windows Forms, and can be used both for visual  and logical organization. I hope this article is interesting. In case of any error or problem with the code feel free to comment below. Thanks for reading the article.


Similar Articles