Designing Windows Forms
When designing a user interface, you must consider the location, size, alignment, and colors. Thankfully,…
The Dock property allows you to dock the control to any of the edges of the form or its container. It’s another way to make your controls intact when you resize the form. When you resize the form, the control remains docked to the edge specified. The Dock property accepts a value from the System.Windows.Forms.DockStyle enumeration. The following are the values available in this enumeration.
|Bottom||The administration’s base edge is docked to exceptionally modest edge of its containing control.|
|Fill||All the perimeters of the management area unit docked to all or any the perimeters of its containing management and is sized suitably.|
|Left||The control’s left edge is docked to the left edge of its containing control.|
|Right||The control’s right edge is docked to the right edge of its containing control.|
|None||The control is not docked.|
|Top||The control’s top edge is docked to the top edge of its containing control.|
System.Windows.Forms.DockStyle Enumeration Values
Let’s try docking a button control into different edges of the form.
To dock a control, select the control to dock and go to Properties Window.
Find the Dock property and then click the dropdown button. You will be presented with a small window with multiple buttons specifying where to dock the control.
The center square means that you will use the DockStyle.Fill value for the Dock property. The following screenshots shows the effect of docking the control to different edges.
If you have multiple controls and use the same docking values, then they will be placed beside or above each other.