Panel Control is a container control which is used to hold child controls. Panel Control is the very useful control in windows application.
Properties
The following are the main properties which are mostly used.
Name
Name property is used to give an identity to panel control. By using this property, one can call our control at the coding time.
Visible
All the controls must have the visible property. Visible property is used to hide or show the control. The visible property has the Boolean values. By default, visible property set to True. If one want to hide the control, then set the visible property as False.
Visible property of panel control plays an important role. One can also change the appearance of the panel control using the appearance properties.
Example
Follow the below steps to know about the panel control and its usage.
Step 1
Drag and drop the panel control on to the form. Now, place the controls inside the panel control as shown in the below figure.
Step 2
Take the another panel control and place beside the first-panel control. Now, move the second control on to the first panel control.
To move the panel, select the panel and click on the Left Arrow Button in the keyboard until the second-panel control covers the first panel control completely.
Note
Make sure that the two panel controls have the same size or not. If not, give the same size for two-panel controls using size property in the properties window
Step 3
After moving the second-panel control on the first panel control, the window will look like the following figure.
Step 4
Now, place the controls inside the second-panel control as shown in the below figure.
Step 5
Set the visible property to false for the second panel control.
Write the below code under the button control's click events as shown below.
[csharp] private void btnHome_Click(object sender, EventArgs e)
{
pnlHome.Visible = true; // Makes panel2 as visible
pnlWelcome.Visible = false;// Makes panel1 as invisible
}
private void btnBack_Click(object sender, EventArgs e)
{
pnlHome.Visible = false;// Makes panel2 as invisible
pnlWelcome.Visible = true;// Makes panel1 as visible
}[/csharp]
Step 6
Press f5 to run the application. Then, the window will be displayed as follows.
Step 7
Now, click on the Go to Home button. The click event makes second panel control as visible and first panel control as invisible. The following window shows the second panel control.
If one want to go back to the first panel control, click on the Back button. This button click event makes second panel control as invisible and first panel control as visible.
This is the usage of panel control. One can hide the controls as a group. Instead of setting visible as false for all the controls, and can set the panel control as invisible.