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
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.
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.
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.
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.
STEP 3 - Coding
Follow the coding given below in the screenshot for panel cotrol in the windows forms application.
- private void button1_Click(object sender, EventArgs e)
- {
- if (index > 0)
- listpanel[--index].BringToFront();
- }
-
- private void Form1_Load(object sender, EventArgs e)
- {
- listpanel.Add(panel1);
- listpanel.Add(panel2);
- listpanel.Add(panel3);
- listpanel[index].BringToFront();
- }
-
- private void button2_Click(object sender, EventArgs e)
- {
- if (index < listpanel.Count - 1)
- listpanel[++index].BringToFront();
- }
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
Previous button is clicked and page 2 is navigated to page 1
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.