SizeToContent相当于一个WinForm?SizeToContent、WinForm

2023-09-08 08:40:50 作者:吃饭睡觉打豆豆╯

在与WPF玩,我发现了 SizeToContent 方法,这使我动态地创建一个窗口的内容,然后让它自动调整大小以适合其内容。

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.

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

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

我用自动调整大小和 AutoSizeMode ,但它不能正确的大小,以它的内容。

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

有没有一种方法来创建具有适应其内容的大小控制一个WinForm,如在WPF?

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

谢谢

推荐答案

据我记得这是一个有点棘手,Windows窗体。基本上你需要使用自动调整大小容器(如TableLayoutPanel中,等 - 和他们的自动调整大小属性设置为)在专门的形式。铺设了控制与码头不起作用。

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.

 
精彩推荐