Export (0) Print
Expand All

Panel Class

Represents a Windows Panel control.

For a list of all members of this type, see Panel Members.

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Windows.Forms.Control
            System.Windows.Forms.ScrollableControl
               System.Windows.Forms.Panel
                  System.Windows.Forms.Design.ComponentEditorPage
                  System.Windows.Forms.TabPage

[Visual Basic]
Public Class Panel
   Inherits ScrollableControl
[C#]
public class Panel : ScrollableControl
[C++]
public __gc class Panel : public ScrollableControl
[JScript]
public class Panel extends ScrollableControl

Thread Safety

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

Remarks

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.

Example

[Visual Basic, C#, C++] The following 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 assumes 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);
}


[C++] 
public:
    void CreateMyPanel() {
        Panel __gc *panel1 = new Panel();
        TextBox __gc *textBox1 = new TextBox();
        Label __gc *label1 = new 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 = S"label1";
        label1->Size = System::Drawing::Size(104, 16);
        textBox1->Location = System::Drawing::Point(16,32);
        textBox1->Text = S"";
        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);
    };

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Windows.Forms

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

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

See Also

Panel Members | System.Windows.Forms Namespace | GroupBox

Show:
© 2014 Microsoft