【发布时间】:2013-04-30 11:41:40
【问题描述】:
我的 C# Windows 窗体应用程序中有一些控件(组框、表格、网格视图等),我想根据屏幕宽度/高度来缩放它们。
例如,屏幕从 640x480 开始,然后最大化到 1920x1200。
我希望能够增加控件的宽度/高度,以便在调整窗口大小后它们看起来完全相同。
在不手动设置每个宽度/高度属性的情况下,最好的方法是什么?
【问题讨论】:
标签: c# winforms size height width
我的 C# Windows 窗体应用程序中有一些控件(组框、表格、网格视图等),我想根据屏幕宽度/高度来缩放它们。
例如,屏幕从 640x480 开始,然后最大化到 1920x1200。
我希望能够增加控件的宽度/高度,以便在调整窗口大小后它们看起来完全相同。
在不手动设置每个宽度/高度属性的情况下,最好的方法是什么?
【问题讨论】:
标签: c# winforms size height width
在不手动设置每个宽度/高度属性的情况下,最好的方法是什么?
您可以使用Anchor 和Dock 属性来让控件根据其包含的元素进行缩放,而不是指定宽度和高度。
或者,您可以使用TableLayoutPanel 或FlowLayoutPanel 来安排您的控件。
【讨论】:
我相信你想要控件的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 选择表单上的所有控件,然后将锚属性设置为顶部、底部、左侧和右侧。
【讨论】: