UserControl Dock / Anchor无法正常工作

时间:2017-11-06 19:26:03

标签: c# .net winforms

这是一个完整的简单案例:

  1. 我创建了 UserControl 。并在其上添加了按钮 Anchor ed右上角。
  2. Dock.Fill 编辑 Form1 中的 UserControl
  3. 按钮在执行时位置不正确(尽管它在Designer中)。

    截图:

    UserControl设计师:

    enter image description here

    Form设计师:

    enter image description here

    执行:

    enter image description here

    执行,调整大小。如您所见,这没有任何帮助:

    enter image description here

    我尝试将计算机的文字大小从125%更改为100%,但这也无济于事。 Windows 10,VS 2017,.Net 4.7.1。我还尝试在其LoadParentChanged事件处理程序及其构造函数中设置UserControl的Dock。没有变化。

    那么如何让按钮保持锚定?

    编辑(它似乎与文字大小不同于100%有关)

    经过大量的摆弄后,我现在看到在更改为100%大小的文本后(在System-Display下的Settings应用程序中。包括注销和打开),清理并重建解决方案,然后再更改回125%它工作了一段时间。我无法找到确切的限制。

1 个答案:

答案 0 :(得分:1)

@ispiro,您可以尝试在VisualStudio进程中禁用DPI感知并查看它是否有帮助。这是一篇博文,指定要设置的注册表项: https://code4ward.net/2016/11/29/visual-studio-winforms-designer-on-highdpi/