HomeSearch

Panel, Windows Forms (Create Group of Controls)

This article describes ways to use Panel in Windows Forms. Panel organizes controls in a group.
Panel creates a group of controls. This control provides a simple frame for putting sub-controls inside. These sub-controls include buttons and text boxes. It further provides an optional border and ways to change its visibility.
To start, please open your Visual Studio Windows Forms project and open the Toolbox, where you can then double-click on the Panel icon. Next, try right-clicking on the Panel in the form and selecting Properties.

Also: You might want to change the BorderStyle, which you can set to Fixed3D to make the Panel look like the example screenshot.

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.

And: When the controls are inside the Panel, they will be affected by the Enabled property of the Panel and the Visible property.

Note: In the example, we added two Button controls to the inside of the Panel control.

Borders. The default Panel does not have a visible border. This is ideal for some programs. But for others, using the Fixed3D or FixedSingle border style is more appropriate. This may also look better.

Review: As you may know from other controls, FixedSingle is a single dark line while the Fixed3D style is an inset, shaded border.

Enabled. What happens when you set the Enabled property of the Panel to False? All of the enclosed controls in the Panel, such as buttons or text boxes, will become inactive and grayed out. They cannot be used by the mouse or the keyboard.

And: Instead of dealing with many text boxes or buttons separately, you can change many controls' states at once with the Panel this way.

Setting Visible property. Also, the Visible property of the Panel affects all the enclosed controls. So if you set the Visible property to False, you will hide all of the sub-controls inside the Panel as well as the Panel itself.
Summary. The Panel control is a container or grouping mechanism in Windows Forms, and can be used both for visual and logical organization. With its border options, you can visually organize your program's sub-controls.

And: With its ability to affect the state of all its enclosed controls, you can reduce your program's logical complexity.

© 2007-2020 Sam Allen. Every person is special and unique. Send bug reports to info@dotnetperls.com.
Home
Dot Net Perls