当前位置:编程学习 > C#/ASP.NET >>

Working with Anchoring and Docking Properties(ZT)

答案: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

Member Name

Description

上一个:抛砖引玉——XP风格的按钮源代码
下一个:穿针引线:一个不完全的对代码加亮的代码,大家可以对其进行扩展!(原创)

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,