SizeToContent 相当于 WinForm 吗?
在使用 WPF 时,我发现了 SizeToContent方法,它使我能够动态创建窗口的内容,然后自动调整其大小以适合其内容。
我尝试使用 WinForms 做同样的事情,但失败了。
我使用了 AutoSize 和 AutoSizeMode,但无法正确调整大小它的内容。
有没有办法创建一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,这在 Windows 窗体中有点棘手。基本上,您需要在表单中专门使用自动调整大小的容器(例如 TableLayoutPanel 等,并将其
AutoSize
属性设置为true
)。使用Anchor
和Dock
布局控件不起作用。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 totrue
) in the form exclusively. Laying out controls withAnchor
andDock
does not work.