This documentation is archived and is not being maintained.

Panel Class

Used to group collections of controls.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public class Panel : ScrollableControl

A Panel is a control that contains other controls. You can use a Panel to group collections of controls such as a group of RadioButton controls. As with other container controls such as the GroupBox control, if the Panel control's Enabled property is set to false, the controls contained within the Panel will also be disabled.

The Panel control is displayed by default without any borders. You can provide a standard or three-dimensional border using the BorderStyle property to distinguish the area of the panel from other areas on the form. Because the Panel control derives from the ScrollableControl class, you can use the AutoScroll property to enable scroll bars in the Panel control. When the AutoScroll property is set to true, any controls located within the Panel (but outside of its visible region), can be scrolled to with the scroll bars provided.

The Panel control does not display a caption. If you need a control similar to a Panel that can display a caption, see the GroupBox control.

The following code example creates a Panel control and adds a Label and a TextBox to the Panel. The Panel control is displayed with a three-dimensional border to distinguish where the Panel control is located in relation to other objects on the form. This example requires that the method defined in this example is called from within an existing form and that the System.Drawing namespace has been added to the source code for the form.

public void CreateMyPanel()
   Panel panel1 = new Panel();
   TextBox textBox1 = new TextBox();
   Label label1 = new Label();

   // Initialize the Panel control.
   panel1.Location = new Point(56,72);
   panel1.Size = new Size(264, 152);
   // Set the Borderstyle for the Panel to three-dimensional.
   panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;

   // Initialize the Label and TextBox controls.
   label1.Location = new Point(16,16);
   label1.Text = "label1";
   label1.Size = new Size(104, 16);
   textBox1.Location = new Point(16,32);
   textBox1.Text = "";
   textBox1.Size = new Size(152, 20);

   // Add the Panel control to the form. 
   // Add the Label and TextBox controls to the Panel.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0