Most of you have heard ofand probably usedthe new anchoring and docking properties available to Windows form controls. They enable controls to automatically resize or reposition themselves as the form resizes. This saves time that would normally be spent writing inane, non-productive resizing code just to make the forms look the same. This article explains how to use the new properties to save yourself some coding time.
The Docking feature attaches a control to the edge of its container. When a control is docked to an edge of it's container, it will always stick to that edge. The control will also resize itself to fully fit the edge of the container and also resizes as the container is resized. The Dock property of the Form control can be set to any one of the six values, Top, Bottom, Left, Right, Fill, and None.
By default the Dock property is set to None. To graphically set the Dock property, click on the dropdown at the right of the Dock property in the Properties window. Then, select the edge to which you want to dock the control, or dock it to the center (Fill) or set to None.
Controls can also be docked by code:
Me.Button1.Dock = System.Windows.Forms.DockStyle.Left
this.button1.Dock = System.Windows.Forms.DockStyle.Left;