Export (0) Print
Expand All

Aligning Your 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:

SettingEffect on your control
DockStyle.BottomDocks to the bottom of the form.
DockStyle.FillFills all remaining space in the form.
DockStyle.LeftDocks to the left side of the form.
DockStyle.NoneDoes not dock anywhere, and it appears at the location specified by its Location Property.
DockStyle.RightDocks to the right side of the form.
DockStyle.TopDocks to the top of the form.

These values can be set in code, but they are usually set at design time in the Properties window.

To set the Dock property for your control at run time

  • Set the Dock property to the appropriate value in code.
    ' Visual Basic
    ' To set the Dock property internally.
    Me.Dock = DockStyle.Top
    ' To set the Dock property from another object.
    UserControl1.Dock = DockStyle.Top
    
    // C#
    // To set the Dock property internally.
    this.Dock = DockStyle.Top;
    // To set the Dock property from another object.
    UserControl1.Dock = DockStyle.Top;
    

To set the Dock property for your control at design time

  1. In the designer, select your control.
  2. In the Properties window, click the drop-down box next to the Dock property.

    A graphical interface representing the six possible Dock settings is displayed.

  3. Choose the appropriate setting.

    Your control will now dock in the manner specified by the setting.

See Also

Control Authoring for Windows Forms | Control.Anchor Property

Show:
© 2014 Microsoft