C#的屏幕分辨率和表单显示表单、屏幕分辨率

2023-09-03 05:43:38 作者:青春、献给了小酒桌。

我有一个C#WinForms应用程序,当我给可执行不同用户的应用程序将显示不同大小(根据其屏幕分辨率)。一些应用程序的各部分的不能被看到。

I have a C# WinForms application and when I give the executable to different users the application displays in different sizes (based on their screen resolution). Some of the parts of the application can't be seen.

反正有自动调整大小根据屏幕分辨率的窗口,或者是有其他的方法呢?

Is there anyway to auto-size the window based on the screen resolution, or is there another approach?

编辑:此外,它会出现在不同风格下的不同的操作系统,有没有去规范它的设计

EDIT : furthermore it appears in different styles under different Operating systems, is there away to standardize its design ?

推荐答案

您可以使用的 Control.ScaleControl 和控制。规模

private void MainForm_Load( object sender, EventArgs e )
{
    float width_ratio = (Screen.PrimaryScreen.Bounds.Width / 1280);
    float heigh_ratio = (Screen.PrimaryScreen.Bounds.Height / 800f);

    SizeF scale = new SizeF(width_ratio, heigh_ratio);

    this.Scale(scale);

   //And for font size
   foreach (Control control in this.Controls)
   {
      control.Font = new Font("Microsoft Sans Serif", c.Font.SizeInPoints * heigh_ratio * width_ratio);
   }
}

在的情况下,当开发平台的分辨率是1280×800

In the case when the development platform resolution is 1280x800

据@sixlettervariables的答案停靠和锚定将有助于当然。

According to @sixlettervariables 's answer Docking and anchoring will help of course.