What is Anchoring a control and Docking a control? - C#.NET

What is Anchoring a control and Docking a control?

Anchoring Property

- The forms can be created in such a way that they can be resizeable and for this we need to adjust one of the values of the FormBorderStyle property that is to configure the reusability of the form.

Need for Anchoring

- The Anchor property of Windows Forms controls is used to resize the controls dynamically with the form.
- It describes an anchor position for the control. When a control is anchored to a form and the form is resized, the control maintains the distance between the control and the anchor positions.

Docking Property

- The dock property controls the edges of your form or have them fill the controls container (either a form or a container control).
- An example can be, the Windows Explorer docks its TreeView control to the left side of the window and its ListView control to the right side of the window.
- Whenever a control is docked to an edge of it's container it will always be positioned flush against that edge while the container re-sizes.
- If there are more than one control and is docked to an edge, the controls will not be placed on top of each other.
- If we select Left or Right then the left and right edge of the control is re-sized the same size as the containing control's edge.
- Likewise, if the Top or Bottom is selected then the top and bottom edge of the control is re-sized to the same size as the containing control's edge.
- If Fill is selected, all sides of the control is re-sized to the same size as all the containing control's edges.
- For example, to make a Button control fill the client area of its container, the code is as follows:

button1.Dock = DockStyle.Fill;

- This control is automatically resized to fit the boundaries of the docked edge.
What is ErrorProvider control? - C#.NET
What is ErrorProvider control? - It is a control to provide a feedback about another control that has an error...
Different types of windows control in .NET
Explain the different types of windows control you can create in .NET - Common controls: textbox, button...
How to build a composite control - C#.NET
Explain how to build a composite control - Steps to create a Composite control:..
Post your comment