...
Working with Anchoring and Docking Properties(ZT)
时间:2006-5-21 22:12:02 来源:本站收集整理 作者:佚名
Introduction
In this article let's take an expedition through travel around how Anchoring, Docking Properties of Controls can be used in Windows Forms.
Anchoring Property
In creating a Form containing controls we have to decide whether the Forms should be resizable. Adjust any one of the values to the FormBorderStyle property to configure the reusability of the Form.
Need for Anchoring
To resize controls dynamically with the form, we can use the Anchor property of Windows Forms controls. The Anchor property 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.
For example, if you have a Button control that is anchored to the left, right, and bottom edges of the form, as the form is resized, the button control resizes horizontally so that it matches the same distance from the right and left sides of the form. In addition, the control positions itself vertically so that its location is always the same distance from the bottom edge of the form. The Anchor property can be set to the controls as shown in the figure below in WinDes.exe

When the form is displayed at run time, the control resizes to remain positioned at the same distance from the edge of the form. But certain controls, such as the ComboBox control, have a limit to their height. Anchoring the control to the bottom of its form or container cannot force the control to exceed its height limit.
Controls are anchored to the top and left by default.

For example, if we configure a Button with the following Anchor value.
button1.Anchor = System.WinForms.AnchorStyles.Bottom;
The output is as follows:
Before Resized:

After Resized:

We see that the button maintains its position relative to the Bottom side of the form.
Docking Property:
We can dock controls to the edges of your form or have them fill the controls container (either a form or a container control). 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.
Members
In this article let's take an expedition through travel around how Anchoring, Docking Properties of Controls can be used in Windows Forms.
Anchoring Property
In creating a Form containing controls we have to decide whether the Forms should be resizable. Adjust any one of the values to the FormBorderStyle property to configure the reusability of the Form.
Need for Anchoring
To resize controls dynamically with the form, we can use the Anchor property of Windows Forms controls. The Anchor property 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.
For example, if you have a Button control that is anchored to the left, right, and bottom edges of the form, as the form is resized, the button control resizes horizontally so that it matches the same distance from the right and left sides of the form. In addition, the control positions itself vertically so that its location is always the same distance from the bottom edge of the form. The Anchor property can be set to the controls as shown in the figure below in WinDes.exe

When the form is displayed at run time, the control resizes to remain positioned at the same distance from the edge of the form. But certain controls, such as the ComboBox control, have a limit to their height. Anchoring the control to the bottom of its form or container cannot force the control to exceed its height limit.
Controls are anchored to the top and left by default.

For example, if we configure a Button with the following Anchor value.
button1.Anchor = System.WinForms.AnchorStyles.Bottom;
The output is as follows:
Before Resized:

After Resized:

We see that the button maintains its position relative to the Bottom side of the form.
Docking Property:
We can dock controls to the edges of your form or have them fill the controls container (either a form or a container control). 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.
Members
Member Name ... 分类导航数据载入中...
版权所有 2004-2008 3lian素材网[3lian.com] 最佳分辨率 1024×768
Copyright www.3lian.com All rights reserved. |
