Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Panel Class
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Panel Class

Used to group collections of controls.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
Visual Basic (Declaration)
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<ComVisibleAttribute(True)> _
<DockingAttribute(DockingBehavior.Ask)> _
Public Class Panel _
    Inherits ScrollableControl
Visual Basic (Usage)
Dim instance As Panel
C#
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[ComVisibleAttribute(true)]
[DockingAttribute(DockingBehavior.Ask)]
public class Panel : ScrollableControl
Visual C++
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)]
[ComVisibleAttribute(true)]
[DockingAttribute(DockingBehavior::Ask)]
public ref class Panel : public ScrollableControl
JScript
public class Panel extends 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.

Visual Basic
Public Sub CreateMyPanel()
    Dim panel1 As New Panel()
    Dim textBox1 As New TextBox()
    Dim label1 As 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.
    Me.Controls.Add(panel1)
    ' Add the Label and TextBox controls to the Panel.
    panel1.Controls.Add(label1)
    panel1.Controls.Add(textBox1)
End Sub


C#
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.
   this.Controls.Add(panel1);
   // Add the Label and TextBox controls to the Panel.
   panel1.Controls.Add(label1);
   panel1.Controls.Add(textBox1);
}


Visual C++
public:
   void CreateMyPanel()
   {
      Panel^ panel1 = gcnew Panel;
      TextBox^ textBox1 = gcnew TextBox;
      Label^ label1 = gcnew Label;

      // Initialize the Panel control.
      panel1->Location = System::Drawing::Point( 56, 72 );
      panel1->Size = System::Drawing::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 = System::Drawing::Point( 16, 16 );
      label1->Text = "label1";
      label1->Size = System::Drawing::Size( 104, 16 );
      textBox1->Location = System::Drawing::Point( 16, 32 );
      textBox1->Text = "";
      textBox1->Size = System::Drawing::Size( 152, 20 );

      // Add the Panel control to the form.
      this->Controls->Add( panel1 );
      // Add the Label and TextBox controls to the Panel.
      panel1->Controls->Add( label1 );
      panel1->Controls->Add( textBox1 );
   }

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

    // Initialize the Panel control.
    panel1.set_Location(new Point(56, 72));
    panel1.set_Size(new Size(264, 152));

    // Set the Borderstyle for the Panel to three-dimensional.
    panel1.set_BorderStyle(System.Windows.Forms.BorderStyle.Fixed3D);

    // Initialize the Label and TextBox controls.
    label1.set_Location(new Point(16, 16));
    label1.set_Text("label1");
    label1.set_Size(new Size(104, 16));
    textBox1.set_Location(new Point(16, 32));
    textBox1.set_Text("");
    textBox1.set_Size(new Size(152, 20));

    // Add the Panel control to the form.
    this.get_Controls().Add(panel1);

    // Add the Label and TextBox controls to the Panel.
    panel1.get_Controls().Add(label1);
    panel1.get_Controls().Add(textBox1);
} //CreateMyPanel

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 Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, 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
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker