繁体   English   中英

C#Winform屏幕分辨率

[英]c# winform screen resolution

我有一个C#WinForms应用程序,当我将可执行文件提供给不同的用户时,该应用程序以不同的大小显示(基于他们的屏幕分辨率)。 该应用程序的某些部分看不到。

如何为表单设置绝对1280X800,并确保无论分辨率如何,表单大小都不会改变!

您可以使用Control.ScaleControlControl.Scale

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);
   }
}

希望这可以帮助。

使用窗体的MaximumSize属性。

form.MaximumSize = new Size(1280, 800);

如果您不希望用户将其设置为小于所需的大小,则还可以设置MinimumSize。

您可以改而设计GUI,以便它更轻松地上下滚动。您可以利用以下内容

布局经理

对接

锚点

物业

Screen.PrimaryScreen.WorkingArea

对于表单大小和位置非常有用。 例如此代码:

this.Width = Screen.PrimaryScreen.WorkingArea.Width/2;
this.Height = Screen.PrimaryScreen.WorkingArea.Height/2;
this.Top = (Screen.PrimaryScreen.WorkingArea.Top + Screen.PrimaryScreen.WorkingArea.Height)/4;
this.Left = (Screen.PrimaryScreen.WorkingArea.Left + Screen.PrimaryScreen.WorkingArea.Width)/4;

将执行它的表单放在屏幕中间,并将其大小调整为屏幕的一半。

在计算屏幕尺寸时,WorkingArea var用于排除任务栏和桌面上的其他停靠项之类的东西。

希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM