做最好的办法的WinForms调整大小?最好的、大小、办法、WinForms

2023-09-07 02:38:23 作者:守望先锋id温柔 守望先锋温柔游戏名

我工作的一个相当大的C#项目有很多的WinForms,尽管你可以调整的形式,形式要素不具有可扩展。

I am working on a largish c# project with a lot of winforms that, even though you can resize the form, the elements in the form don't scale.

我怎样才能让表单元素(如datagridview的,文本区的,等等),当用户改变窗体的大小尺度

How can I make the form elements (such as the datagridview, text area's, etc) scale when the user changes the size of the form.

几乎所有的从一个特定的形式形式的子类,所以如果有什么东西我可以在基类做,那简直太好了。

Nearly all the forms subclass from one specific form so if there's something I can do in the base class, that'd be great.

推荐答案

您应该设置码头在表单中的控件的属性。

You should set the Anchor and Dock properties on the controls in the forms.

属性控制控件的哪些边缘绑定或捆绑到它的形成相应的边缘。 例如,如果您设置,和其父底部的控件的底部边缘之间的距离不会改变,因此,在您调整窗体控件将下移。 如果设置顶部|底部,控制将调整为垂直调整你的形式。

The Anchor property controls which edges of a control are "bound" or "tied" to the corresponding edges of its form. For example, if you set Anchor to Bottom, the distance between the control's bottom edge and the bottom of its parent will not change, so the control will move down as you resize the form. If you set Anchor to Top | Bottom, the control will resize vertically as you resize the form.

要进行控制调整的形式,将来四面,或者设置码头填写

To make a control resize with the form, set the Anchor to all four sides, or set Dock to Fill.