[英]How to dock to the top and the left
With An anchor I can write the following line: 使用锚点我可以写下以下行:
myControl.Anchor = (AnchorStyles.Top | AnchorStyles.Left);
And it will anchor myControl
to the left and the top. 它会将myControl
锚定在左侧和顶部。
Why can't I do the following: 为什么我不能做以下事情:
myControl.Dock = (DockStyle.Top | DockStyle.Left);
I can write the above line, but all it does is set the DockStyle
to left. 我可以编写上面的代码,但它只是将DockStyle
为左边。
Any thoughts/reasons for this? 有什么想法/原因吗?
The reason you cannot do this is because setting a DockStyle
basically docks/fills the entirity of the specified edge. 你不能这样做的原因是因为设置DockStyle
基本上停靠/填充指定边缘的整体性。
For example, DockStyle.Left
means that the height of the item being docked will always be the height of the container and the the X,Y location will always be 0, 0. 例如, DockStyle.Left
表示停靠项目的高度始终是容器的高度,X,Y位置始终为0,0。
DockStyle.Top
means that the width of the item will always be the width of the container and the location will always be 0,0. DockStyle.Top
表示项目的宽度始终是容器的宽度,位置始终为0,0。
Setting DockStyle.Top
and DockStyle.Left
would essentially give you DockStyle.Fill
. 设置DockStyle.Top
和DockStyle.Left
本质上会给你DockStyle.Fill
。 Ie the same width and height as the container. 即与容器相同的宽度和高度。
A Dock
is a pre-determined anchor set, whereas an Anchor
is a custom dock configuration. Dock
是预定的锚点集,而Anchor
是自定义的Dock配置。
DockStyle.Top
is the same as Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right)
except that an anchor can sit at any initial position and a dock will move to the far edge. DockStyle.Top
与Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right)
相同,不同的是锚点可以位于任何初始位置,并且码头将移动到远边缘。
The DockStyle
can only be set to one value, as opposed to the Anchor
that can be set to many. DockStyle
只能设置为一个值,而Anchor
可以设置为多个。
That is why there is the Anchor
property so that you can adjust how the control reacts to the form resizing more specifically. 这就是为什么有Anchor
属性,以便您可以调整控件对更具体地调整大小的形式的反应。
你可能正在寻找的是Anchor
属性:
myControl.Anchor = AnchorStyles.Bottom | AnchorStyles.Right
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.