如何停靠到顶部和左侧

发布于 2024-09-14 01:28:56 字数 328 浏览 1 评论 0原文

使用锚点,我可以编写以下行:

myControl.Anchor = (AnchorStyles.Top | AnchorStyles.Left);

它将把 myControl 锚定到左侧和顶部。

为什么我不能执行以下操作:

myControl.Dock = (DockStyle.Top | DockStyle.Left);

我可以编写上面的行,但它所做的只是将 DockStyle 设置为左​​侧。

有什么想法/原因吗?

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.

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.

Any thoughts/reasons for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

长发绾君心 2024-09-21 01:28:56

您无法执行此操作的原因是因为设置 DockStyle 基本上会停靠/填充指定边缘的整体。

例如,DockStyle.Left 表示停靠的项目的高度将始终为容器的高度,并且 X、Y 位置将始终为 0, 0。

DockStyle.Top 意味着项目的宽度将始终是容器的宽度,并且位置将始终是 0,0。

设置DockStyle.TopDockStyle.Left本质上会给你DockStyle.Fill。即与容器的宽度相同。

The reason you cannot do this is because setting a DockStyle basically docks/fills the entirity of the specified edge.

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.Top means that the width of the item will always be the width of the container and the location will always be 0,0.

Setting DockStyle.Top and DockStyle.Left would essentially give you DockStyle.Fill. I.e. the same width and height as the container.

夏至、离别 2024-09-21 01:28:56

Dock 是预先确定的锚点集,而 Anchor 是自定义的锚点配置。

DockStyle.TopAnchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right) 相同,只是锚点可以位于任何初始位置,而停靠点将位于任意初始位置。移动到最远的边缘。

A Dock is a pre-determined anchor set, whereas an Anchor is a custom dock configuration.

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.

长梦不多时 2024-09-21 01:28:56

DockStyle 只能设置为一个值,而 Anchor 可以设置为多个值。

这就是为什么有 Anchor 属性,以便您可以更具体地调整控件对表单大小调整的反应方式。

The DockStyle can only be set to one value, as opposed to the Anchor that can be set to many.

That is why there is the Anchor property so that you can adjust how the control reacts to the form resizing more specifically.

征棹 2024-09-21 01:28:56

您正在寻找的可能是 Anchor 属性:

myControl.Anchor = AnchorStyles.Bottom  | AnchorStyles.Right

May be what you are looking for is the Anchor attribute:

myControl.Anchor = AnchorStyles.Bottom  | AnchorStyles.Right
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文