SizeToContent equivalent for a WinForm?

无人久伴 提交于 2019-11-28 11:19:24

问题


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,


回答1:


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.



来源:https://stackoverflow.com/questions/5310666/sizetocontent-equivalent-for-a-winform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!