简体   繁体   English

如何停靠在顶部和左侧

[英]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.TopDockStyle.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.TopAnchor = (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.

相关问题 使用带有MaximumSize的WinForms Dock; 我希望它居中而不是左上方 - using WinForms Dock with MaximumSize; I want it centered not top left 如何在metaFile的左上方绘制 - How to draw at top left of metaFile 如何将两个面板的一侧与顶部和填充的停靠属性重叠? - How to overlap one side of two panels with dock properties of Top and Fill for each? 如何扩展此依赖项属性示例以重新创建DockPanel.Dock =“ Top”之类的依赖项属性? - How can I extend this dependency property example to recreate a DockPanel.Dock=“Top”-like dependency property? 如何隐藏Dock面板名称我需要在顶部显示Dock面板名称,但是在Docking时它也显示在底部..我必须从底部隐藏它 - How to Hide Dock Pannel Name I need the Dock pannel name on top but while Docking it shows in bottom also .. I have to hide it from bottom 控制Dock.Top顺序没有InitializeComponent() - Control Dock.Top order without InitializeComponent() Dock-> Top控件的顺序问题 - Problem with order of Dock->Top controls 如何在Monodroid中停靠控件? - How to Dock a control in Monodroid? 如何在左/上/右/下改变矩形 - How to change Rectanlge Left/Top/Right/Bottom 如何更改datagridview左上角单元格的文本? - How to change text of the top left cell of a datagridview?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM