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
- public partial class Form1: Form {
- List < Panel > listPanel = new List < Panel > ();
- int Index;
- public Form1() {
- InitializeComponent();
- }
- private void button2_Click(object sender, EventArgs e) {
- if (Index < listPanel.Count - 1) listPanel[++Index].BringToFront();
- }
- private void Form1_Load(object sender, EventArgs e) {
- listPanel.Add(panel1);
- listPanel.Add(panel2);
- }
- private void button1_Click(object sender, EventArgs e) {
- if (Index > 0) listPanel[--Index].BringToFront();
- }
- }
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