【问题标题】:Resize in Windows Forms controls along with form resize在 Windows 窗体控件中调整大小以及窗体调整大小
【发布时间】:2013-04-30 11:41:40
【问题描述】:

我的 C# Windows 窗体应用程序中有一些控件(组框、表格、网格视图等),我想根据屏幕宽度/高度来缩放它们。

例如,屏幕从 640x480 开始,然后最大化到 1920x1200。

我希望能够增加控件的宽度/高度,以便在调整窗口大小后它们看起来完全相同。

在不手动设置每个宽度/高度属性的情况下,最好的方法是什么?

【问题讨论】:

    标签: c# winforms size height width


    【解决方案1】:

    在不手动设置每个宽度/高度属性的情况下,最好的方法是什么?

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

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

    【讨论】:

    • 这是有道理的,一直在玩它,但我的设计是非标准的,Dock 只提供顶部、底部和 3 个中心项目。我可以以某种方式制作我的自定义底座吗?
    • @sd_dracula 您无法自定义 - 您需要考虑标准布局。不过,如果您使用“网格”样式,TableLayoutPanel 可能是一种更简单的方法。
    【解决方案2】:

    我相信你想要控件的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 选择表单上的所有控件,然后将锚属性设置为顶部、底部、左侧和右侧。

    【讨论】:

    • 对齐它们很好,但我希望它们根据表单的新宽度/高度扩展它们的宽度/高度。也会这样做吗?
    猜你喜欢
    • 2012-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多