Export (0) Print
Expand All
10 out of 31 rated this helpful - Rate this topic

Panel Class

Used to group collections of controls.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
[ComVisibleAttribute(true)] 
public class Panel : ScrollableControl
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
/** @attribute ComVisibleAttribute(true) */ 
public class Panel extends ScrollableControl
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
ComVisibleAttribute(true) 
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.

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);
}


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

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
         System.Windows.Forms.ScrollableControl
          System.Windows.Forms.Panel
             Derived Classes
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 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.