Skip to main content
 首页 » 编程设计

c#之窗口自动调整大小不起作用

2024年02月13日13unruledboy

我有一个 WinForms 应用程序,我想以任何分辨率运行它,我也不想改变位置和空间 b/w 不同的控件。

这是第一种情况下的快照 但是在更改 resolution 之后看起来像这样 我想根据分辨率,它的控件会自动调整它们的大小以保持它们之间的空间。

请您参考如下方法:

您可以使用 Anchor或 Dock控件的属性。
如果您不想改变控件之间的相对定位。
根据 msdn:-

Use the Anchor property to define how a control is automatically resized as its parent control is resized. Anchoring a control to its parent control ensures that the anchored edges remain in the same position relative to the edges of the parent control when the parent control is resize

和

Use the Dock property to define how a control is automatically resized as its parent control is resized. For example, setting Dock to DockStyle.Left causes the control to align itself with the left edges of its parent control and to resize as the parent control is resized. Controls are docked in their Z-order, which is the visual layering of controls on a form along the form's Z-axis (depth). A control can be docked to one edge of its parent container or can be docked to all edges and fill the parent container.

为了让你的表单解析更友好,你为什么不试试这个:-

    this.WindowState = WindowState.Maximized