我想恢复表单的大小,我使用了以下代码。
我从这个 thread 得到了一个想法.
我发现在某些机器上(特别是 Windows10),当我重新打开这个特定的表单时,表单的宽度会加倍。
我猜这可能是屏幕分辨率的缩放问题,但我无法重现。
因为我没有计算而是直接存储了表单的大小,所以我不知道去哪里看。
我将使用远程助手并尝试找出发生这种情况的原因。我将分享我的发现。
private void Form_Load(object sender, EventArgs e)
{
this.RestoreWindowPosition();
}
private void SaveWindowPosition()
{
Properties.Settings.Default.ReviewFormState = this.WindowState;
if (this.WindowState == FormWindowState.Normal)
{
Properties.Settings.Default.ReviewFormLocation = this.Location;
Properties.Settings.Default.ReviewFormSize = this.Size;
}
else
{
Properties.Settings.Default.ReviewFormLocation = this.RestoreBounds.Location;
Properties.Settings.Default.ReviewFormSize = this.RestoreBounds.Size;
}
Properties.Settings.Default.ReviewFormHasSetDefaults = true;
Properties.Settings.Default.Save();
}
private void Form_FormClosing(object sender, FormClosingEventArgs e)
{
this.SaveWindowPosition();
}
private void RestoreWindowPosition()
{
if (Properties.Settings.Default.ReviewFormHasSetDefaults)
{
this.WindowState = Properties.Settings.Default.ReviewFormState;
this.Location = Properties.Settings.Default.ReviewFormLocation;
this.Size = Properties.Settings.Default.ReviewFormSize;
}
}
远程 session 之后
正如我之前所说,我完成了远程 session 。我发现这是因为规模问题。但是,这似乎很奇怪。我检查了 [显示设置 - 比例和布局] 菜单,它是 125%。然后我打开表格并重复。我发现表单大小在增长。我认为这是第一次尝试的 1.25 倍。我所做的是将比例更改为 100%,然后打开并重复同样的操作。这一次,我什么也没找到;表格大小相同。
我的中间步骤结论是我需要保存一个纯尺寸的表格。我会按比例翻译。然后我想,我可以获得表格的真实大小。我不太确定我会尝试分享我发现的让某人参与其中的发现。
@Jimi 和@Louis Go 我希望有一天我也能帮助你。谢谢你帮助我。
最佳答案
吉米:
Make your application DpiAware if haven't. Start from here: How to configure an app to run correctly on a machine with a high DPI setting (e.g. 150%)?, then take a look at the app.config settings and to High DPI support in Windows Forms (consider and test the
PerMonitorV2
setup). Take into consideration the Form'sAutoScaleMode
. See the difference betweenDpi
andFont
.
关于c# - Windows10,当我打开窗体时,窗体的宽度大小似乎保持 1.25 倍大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60106059/