This documentation is archived and is not being maintained.

Control.Dock Property

Gets or sets which edge of the parent container a control is docked to.

[Visual Basic]
Public Overridable Property Dock As DockStyle
public virtual DockStyle Dock {get; set;}
public: __property virtual DockStyle get_Dock();
public: __property virtual void set_Dock(DockStyle);
public function get Dock() : DockStyle;
public function set Dock(DockStyle);

Property Value

One of the DockStyle values. The default is None.


Exception Type Condition
InvalidEnumArgumentException The value assigned is not one of the DockStyle values.


A control can be docked to one edge of its parent container or can be docked to all edges and fill the parent container. For example, if you set this property to DockStyle.Left, the left edge of the control will be docked to the left edge of its parent control. Additionally, the docked edge of the control is resized to match that of its container control. Controls are docked in order of their z-order.

For more information about anchoring and docking controls, see Walkthrough: Creating a Multipane User Interface with Windows Forms.

Notes to Inheritors:  When overriding the Dock property in a derived class, use the base class's Dock property to extend the base implementation. Otherwise, you must provide all the implementation. You are not required to override both the get and set methods of the Dock property; you can override only one if needed.


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

See Also

Control Class | Control Members | System.Windows.Forms Namespace | DockStyle | Anchor | ScrollableControl.DockPaddingEdges | Layout