我有一个 C# WinForms 应用程序,当我将可执行文件提供给不同的用户时,该应用程序以不同的大小显示(基于他们的屏幕分辨率)。无法看到应用程序的某些部分。
如何为我的表单设置绝对 1280X800 并确保无论分辨率如何,表单大小都不会改变!
最佳答案
您可以使用 Control.ScaleControl和 Control.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/