WinForms调整控件以及窗体resize

我在c#WinForms应用程序中有一些控件(组框,表格,gridview等),我想根据屏幕宽度/高度来缩放它们。

例如,屏幕从让我们说640×480开始,然后它最大化到1920×1200。

我无法增加控件的宽度/高度,因此在窗口重新resize后它们看起来完全相同。

如果不手动设置每个宽度/高度属性,最好的方法是什么?

如果不手动设置每个宽度/高度属性,最好的方法是什么?

您可以使用AnchorDock属性来控制根据其包含元素进行缩放,而不是指定宽度和高度。

或者,您可以使用TableLayoutPanelFlowLayoutPanel来排列控件。

我相信你想要的是控件的Anchor属性。

顾名思义,此属性强制控件将自身锚定在父窗体或控件内的相对位置或绝对位置。 此属性有四个值可以打开或关闭:

 Top -- Indicates that the control should keep its top edge stationary in respect to the parent form (or control) top edge. Bottom -- Indicates that the control should keep its bottom edge stationary in respect to the parent form (or control) bottom edge. Left -- Indicates that the control should keep its left edge stationary in respect to the parent form (or control) left edge. Right -- Indicates that the control should keep its right edge stationary in respect to the parent form (or control) right edge. 

IIRC您想要的是使用Ctrl + A选择表单上的所有控件,然后将锚属性设置为顶部,底部,左侧和右侧。