Udostępnij za pośrednictwem


How to: Dock Controls on Windows 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 Windows Forms controls to define the docking mode.

Note

Controls are docked in reverse z-order.

The Dock property interacts with the AutoSize property. For more information, see AutoSize Property Overview.

To dock a control

  1. Select the control that you want to dock.

  2. In the Properties window, click the arrow to the right of the Dock property.

    An editor is displayed that shows a series of boxes representing the edges and the center of the form.

  3. Click the button that represents the edge of the form where you want to dock the control. To fill the contents of the control's form or container control, click the center box. Click (none) to disable docking.

    The control is automatically resized to fit the boundaries of the docked edge.

    Note

    Inherited controls must be Protected to be able to be docked. To change the access level of a control, set its Modifier property in the Properties window.

See Also

Tasks

How to: Anchor and Dock Child Controls in a FlowLayoutPanel Control

How to: Anchor and Dock Child Controls in a TableLayoutPanel Control

How to: Anchor Controls on Windows Forms

Concepts

AutoSize Property Overview

Reference

Windows Forms Controls by Function

Other Resources

Windows Forms Controls

Arranging Controls on Windows Forms

Labeling Individual Windows Forms Controls and Providing Shortcuts to Them

Controls to Use on Windows Forms