Multiple Pages On The Form Using Panel Control In A Simple Windows Forms Application

In this article, we will learn how to show multiple pages on the Form using Panel Control in a simple Windows Application. It actually displays many child pages shown in a single form.

Panel Control

The Panel Control is a container that controls a group of similar child controls. One of the uses of a Panel Control is to show multiple child forms in a single parent form and hide the child forms using controls.

Create a panel control

It is a simple way to drag and drop from the tools in the Visual Studio. It is available in all the Visual Studio versions.

Step 1

Click New >> Project >> Visual C# >> Windows >> Windows Forms Application. Enter your Project name and click OK.

Step 2

Click the View->Select Toolbox. We are using this Toolbox to design the form in Windows applications. In the Toolbox, we have to add Panel Control box.

 

Step 3

Click the View->Select Toolbox. We are using this Toolbox to design the form in Windows application. Add two buttons and give names as Previous and Next.



Step 4
 

Click the Previous button properties(button1_Click) and Next Button (button2_Click) to be completed for the event to make the function more accurate.

C# CODE
  1. public partial class Form1: Form {  
  2.     List < Panel > listPanel = new List < Panel > ();  
  3.     int Index;  
  4.     public Form1() {  
  5.         InitializeComponent();  
  6.     }  
  7.     private void button2_Click(object sender, EventArgs e) {  
  8.         if (Index < listPanel.Count - 1) listPanel[++Index].BringToFront();  
  9.     }  
  10.     private void Form1_Load(object sender, EventArgs e) {  
  11.         listPanel.Add(panel1);  
  12.         listPanel.Add(panel2);  
  13.     }  
  14.     private void button1_Click(object sender, EventArgs e) {  
  15.         if (Index > 0) listPanel[--Index].BringToFront();  
  16.     }  
  17. }  

Step 5

Create many child lists & given names as Page 1 and page 2. Bind the lists one by one in the picture, as shown below.



Step 6

Press F5 or "Build and Run" the application. When you select the buttons, the list moves to Previous or to Next

 

Finally, we have successfully created multiple pages on the Form using Panel Control in a simple Windows Forms application

X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now