NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Docking Controls on Win Forms

You can dock controls to the edges of your form or have them fill the control's container (either a form or a container control). For example, Windows Explorer docks its TreeView control to the left side of the window and its ListView control to the right side of the window. Use the Dock property for all visible Win Forms controls to define the docking mode.

To dock a control on a form at run time

  1. Open the form that contains the control you want to dock in your code editor.
  2. In a method in your form, set the Dock property for the control that you want to dock. For example, to dock a TreeView control to the left edge of the form add code the following code:
    [Visual Basic]
    Private Sub DockMyControl()
       'Set the TreeView control' to anchor to left.
       trvMain.Dock = DockStyle.Left
    End Sub
    [C#]
    private void DockMyControl()
    {
       ' Set the TreeView control' to anchor to left.
       trvMain.Dock = DockStyle.Left;
    }

    When your form is displayed at run time, the control resizes to the size of the borders the control is docked to.

See Also

Control Manipulation on Win Forms | Controls by Category | Resizing Controls on Win Forms | Setting the Tab Order on Win Forms | Working with Individual Controls | Controls You can Use on Win Forms | Control Technologies and Where to Use Them | Win Form Controls by Function