Panel

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
Exam Prep. Guides
70-505 Study Guide
70-526 Study Guide

1. Forms Controls

2. Integrating Data
3. Printing/Reporting
4. Enhancing Usability
5. Asynchronous Prog.
6. Forms Controls
7. Configure/Deploy

edit
Exam 70-526 Preparation Guide: Group and arrange controls by using the Panel control.


Contents


The Panel control is a container for other controls, customarily used to group related controls. Panels are used to subdivide a form by function, giving the user a logical visual cue of control grouping.

You can add controls to the Panel at design time and runtime. When you move the Panel control, all of its contained controls move too. The Panel control is displayed by default without any borders or scroll bars.


Inheritance hierarchy

System.Object 
  System.MarshalByRefObject 
    System.ComponentModel.Component 
      System.Windows.Forms.Control 
        System.Windows.Forms.ScrollableControl 
          System.Windows.Forms.Panel
            derived Classes...


Useful properties

  • AutoScroll - This property when set to true, allows scroll bars to be displayed.
  • BackColor - The background colour of the Panel is defaulted to System.Drawing.SystemColors.Control, but this can be set to any colour you like.
  • BackgroundImage - Instead of a single colour, an image can be displayed as the background.
  • BorderStyle - This property determines if the panel is outlined with no visible border (None), a plain line (FixedSingle), or a shadowed line (Fixed3D).
  • Controls - Gets the collection of controls contained within the control.
  • Enabled - if this property is set to false, the controls contained within the Panel will also be disabled.
  • TabIndex - Gets or sets the tab order of the control within its container. (inherited from Control)
  • TabStop - Gets or sets a value indicating whether the user can give the focus to this control using the TAB key.
Note:
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.


Docking a Panel in a Form

A Panel can be docked into the parent container, by selecting the Panel and clicking on the Smart Tag icon Image:SmartTagGlyph.jpg. This causes a small menu to appear, simply click on Dock in parent container.

Image:526-32.jpg


To undock the Panel, click on the Smart Tag icon Image:SmartTagGlyph.jpg and select Undock in parent container.

Image:526-33.jpg


Add a control to a Panel manually

The Panel Control MSDN page has the following example showing how to add a Panel and some controls within it.

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


MSDN references


Previous_Page_.gif Next_Page_.gif
© 2007-2008 Mike Kitchen

Personal tools