c# winform 屏幕分辨率

标签 c# windows winforms

我有一个 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);
   }
}

希望这对您有所帮助。

关于c# winform 屏幕分辨率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21281392/

相关文章:

c# - 从不能在文件名中使用的符号中清除字符串

c# - SignalR 自主机断开超时(没有 Global.asax)

c++ - 非阻塞 ConnectNamedPipe 事件未收到信号

c# - 如何将两个文本(.txt)文件合并为一个文件并区分相同的内容?

时间:2019-05-17 标签:c#winform: node expand and collapse in TreeView

c# - 这是使用 Web 服务激活串行 key 的好方法吗?

c# - 何时使用 TryAddSingleton 或 AddSingleton?

javascript - 如何从 node.js 应用程序制作 exe 文件?

c - 如何从 IRP_MJ_CREATE 回调中获取 OpenResult?

c# - 将多个项目添加到同一行的列表框中