What is Anchor and Dock in VB.NET?

The Anchor and Dock properties of a form are two separate properties.


To resize controls dynamically with the form, we can use the Anchor property of Windows Forms controls. A textbox, for example, that is anchored to the left edge of a form will stay in the same position as the form is resized. Anchor position for the control is defined in Anchor properties. When we set the anchor properties of the control of a form and the form is resized , the distance between the control and the anchor position is maintained. By default controls are anchored to the top and left side .


Docking refers to how much space you want the control to take up on the form. If you dock a control to the left of the form, it will stretch itself to the height of the form, but its width will stay the same. 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. When you select the dock property, you see the small editor from which you can select the side on the form in which the control should be docked. By default the dock property of the controls is selected to None .