views:

69

answers:

3

What is the magic that makes components cling to the edges of a form?

I had thought that one must use the resize event of the form and them force each element in the form to resize.

But then I saw some sample code which, even when I am editing the form, the elements seem to adhere to a percentage of the space they take up in the form rather than a set diminsion. In other words, when I am editing the form and resizing it, the panels and the parts inside the form bend their shape such that the edges remain a few pixels from the edges.

But in my own program I have not been able to find where I can duplicate this feature. When I run my program, this

alt text

goes to this

alt text

+1  A: 

You're looking for the Anchor and/or Dock properties.

SLaks
A: 

You are probably refering to anchoring and docking properties of visual controls.

o.k.w
+1  A: 

You are looking for the Anchor property.

In the designer properties of each control there is this setting, which can be set for each side of the parent control.

Setting anchor to left, right and top for example will mean that your control will stay the same distance from these sides of the form when resizing, but when the form is resized downwards, space will open up.


The Dock property is similar, but while the Anchor property fixes the distance to each side, the Dock property attaches the control to the specified side (and even allows a control to be set to fill the parent control).

David Hall