Share via


How to: Align a Control to the Edges of Forms

 

You can make your control align to the edge of your forms by setting the Dock property. This property designates where your control resides in the form. The Dock property can be set to the following values:

Setting Effect on your control
Bottom Docks to the bottom of the form.
Fill Fills all remaining space in the form.
Left Docks to the left side of the form.
None Does not dock anywhere, and it appears at the location specified by its Location property.
Right Docks to the right side of the form.
Top Docks to the top of the form.

There is design-time support for this feature in Visual Studio.

To set the Dock property for your control at run time

  1. Set the Dock property to the appropriate value in code.

    ' To set the Dock property internally.  
    Me.Dock = DockStyle.Top  
    ' To set the Dock property from another object.  
    UserControl1.Dock = DockStyle.Top  
    
    // To set the Dock property internally.  
    this.Dock = DockStyle.Top;  
    // To set the Dock property from another object.  
    UserControl1.Dock = DockStyle.Top;  
    

See Also

Control.Dock
Control.Anchor
Developing Custom Windows Forms Controls with the .NET Framework
How to: Anchor and Dock Child Controls in a FlowLayoutPanel Control
How to: Anchor and Dock Child Controls in a TableLayoutPanel Control
AutoSize Property Overview