SizeToContent 相当于 WinForm 吗?

发布于 2024-10-22 01:10:56 字数 559 浏览 7 评论 0原文

在使用 WPF 时,我发现了 SizeToContent方法,它使我能够动态创建窗口的内容,然后自动调整其大小以适合其内容。

我尝试使用 WinForms 做同样的事情,但失败了。

我使用了 AutoSizeAutoSizeMode,但无法正确调整大小它的内容。

有没有办法创建一个 WinForm,其中的控件可以根据内容的大小进行调整,就像在 WPF 中一样?

谢谢,

When playing with WPF, I discovered the SizeToContent method, which enables me to create dynamically the content of a window, and then have it automatically resized to fit its content.

I try to do the same thing using WinForms, and it fails.

I used the AutoSize and AutoSizeMode, but it fails to correctly size to its content.

Is there a way to create a WinForm with controls that adjust to the size of their content, as in WPF?

Thanks,

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

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

发布评论

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

评论(1

白日梦 2024-10-29 01:10:56

据我所知,这在 Windows 窗体中有点棘手。基本上,您需要在表单中专门使用自动调整大小的容器(例如 TableLayoutPanel 等,并将其 AutoSize 属性设置为 true)。使用 AnchorDock 布局控件不起作用。

As far as I remember this is a bit tricky in Windows Forms. Basically you need to use auto-sizing containers (e.g. TableLayoutPanel, etc. – and set their AutoSize property to true) in the form exclusively. Laying out controls with Anchor and Dock does not work.

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