DockStyle Enumeration


Specifies the position and manner in which a control is docked.

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

public enum DockStyle

Member nameDescription

The control's bottom edge is docked to the bottom of its containing control.


All the control's edges are docked to the all edges of its containing control and sized appropriately.


The control's left edge is docked to the left edge of its containing control.


The control is not docked.


The control's right edge is docked to the right edge of its containing control.


The control's top edge is docked to the top of its containing control.

When a control is docked to an edge of its container, it is always positioned flush against that edge when the container is resized. If more than one control is docked to an edge, the controls appear side by side according to their z-order; controls higher in the z-order are positioned farther from the container's edge.

If Left, Right, Top, or Bottom is selected, the specified and opposite edges of the control are resized to the size of the containing control's corresponding edges. If Fill is selected, all four sides of the control are resized to match the containing control's edges.

The following example creates a GroupBox and sets some of its common properties. The example creates a TextBox and sets its Location within the group box. Next, it sets the Text property of the group box, and docks the group box to the top of the form. Lastly, it disables the group box by setting the Enabled property to false, which causes all controls contained within the group box to be disabled.

// Add a GroupBox to a form and set some of its common properties.
private void AddMyGroupBox()
   // Create a GroupBox and add a TextBox to it.
   GroupBox groupBox1 = new GroupBox();
   TextBox textBox1 = new TextBox();
   textBox1.Location = new Point(15, 15);

   // Set the Text and Dock properties of the GroupBox.
   groupBox1.Text = "MyGroupBox";
   groupBox1.Dock = DockStyle.Top;

   // Disable the GroupBox (which disables all its child controls)
   groupBox1.Enabled = false;

   // Add the Groupbox to the form.

.NET Framework
Available since 1.1
Return to top