Re: Difference between Anchor and Dock properties?
The Anchor and Dock properties manage the position and sizing of controls as the user changes the size of a form.
The Dock property is used to set a control to one of the four edges of the form -- Top, Bottom, Left, or Right -- to dock it to that edge. A docked control will always be positioned flush against the respective edge of it's container form. It's "opposite" size dimention will be modified to take up the entire width or height of the form. In other words, if you set a control's Dock property to Left, that control will always be positioned flush against the left edge of the form, and its height property will be automatically adjusted so that the control takes up the entire height pf the form.
One special value of the Dock property, Fill, causes all four edges of the control to be docked to all four edges of the form. This will always take up the entire inner area of the form.
The Anchor property, allows you to specify any (or all) of the four edges of a form to which you want to control to be anchored. Normally, a control's Anchor property is set to Top, Left, which means that the control's distance from the top and left edges of the form will remain constant, no matter how the form is resized. Changing the Anchor property to some other combination of edges, such as Top, Bottom, Left, will cause the conrol's distance from edges to remain constant as the form is resized. The control's location and size properties are adjusted as necessary to accomplish this.
One use of the Anchor property is to keep the size of an image constant relative to the size of the form containing it.
The Anchor and Dock properties cannot be used at the same time for the same control. If, for example, you set the Anchor property of a control to something other then its default value, and set its Dock property to Bottom, Left, for instance the control's Anchor property reverts to its default value of Top, Left.
When you want a control to remain positioned along one (or more) of the form's edge, use the Dock property. If you want a control's position inside the form (not docked to an edge) to remain constant, use the Anchor property.
|