Your Ads Here

Wednesday, 21 March 2012

Anchor and dock controls or property in C#.NET


It shows how to dock and anchor controls or property in C#.NET
Keywords: C#.NET, C SHARP.NET, align, anchor, docking.

Anchoring and Docking

The Anchor and Dock properties of a form are two separate properties. Anchor refers to the position a control has relative to the edges of the form. A button, for example, that is anchored to the left edge of a form will stay in the same position as the form is resized. 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.

Anchoring

Step 1: Add two buttons to the form, click on the button and take its anchor property in property box, The default is to anchor the control to the Top, Left edge of the form.



Step 2: The button in the middle represents your control. The big white areas are rather confusing - they don't actually do anything! To change the property, you click the smaller grey or white rectangles between the big white rectangle. Click again to deselect it. In the image below, the property has been changed so that the button is anchored to the Top, Left and Right sides of the form:



Step 3: Thus you can change your controls position as you like.

Docking

Docking is similar to Anchoring, but this time the control fills a certain area of the form. To see how it works, click on one of your button and locate the Dock property. 



This time, all the rectangles are like buttons. You can only dock to one side at a time, and the default is None. Click a button to see what it does to your button. Click the middle one, and the button will Fill the whole form.



Docking is quite useful when used with the splitter control and panels, allowing you to create a Windows-style interface.

No comments:

Post a Comment