简体   繁体   English

Windows10,当我打开表单时,表单的宽度大小似乎保持了 1.25 倍

[英]Windows10, A form's width size seems like keeping 1.25 times larger when I open the form

I want to restore the form's size and I used the below codes.我想恢复表单的大小,我使用了以下代码。

I got an idea from this thread .我从这个线程中得到了一个想法。

And I found out on some machines (in particular, Windows10) a form's width keeps doubled when I reopen this specific form.我发现在某些机器上(特别是 Windows10),当我重新打开这个特定的表单时,表单的宽度会加倍。

I'm guessing that it might be scaling issue of screen resolution but I can't reproduce it.我猜这可能是屏幕分辨率的缩放问题,但我无法重现它。

Since I didn't calculate but store the form's size directly, I have no idea where to look.由于我没有计算而是直接存储表单的大小,所以我不知道在哪里看。

I'm going to use a remote assistant and try to figure out why it happened.我将使用远程助手并尝试找出它发生的原因。 I will share what I find.我会分享我发现的。

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

After a remote session远程会话后

As I said earlier, I finished a remote session.正如我之前所说,我完成了一个远程会话。 I found out this is because of a scale issue.我发现这是因为规模问题。 But still, it seems pretty strange.但是,这似乎仍然很奇怪。 I've checked [display settings - scale and layout] menu and it was 125%.我检查了 [显示设置 - 比例和布局] 菜单,它是 125%。 Then I open the form and repeat.然后我打开表格并重复。 I found the form size is growing.我发现表单大小正在增长。 I think it was 1.25 times on the first try.我认为第一次尝试是 1.25 次。 What I did was I changed the scale on 100%, then did the same thing open and repeat.我所做的是将比例更改为 100%,然后打开并重复相同的操作。 For this time, I didn't find anything;这一次,我什么也没找到; the form was in the same size.表格大小相同。

My middle step conclusion is that I need to save a pure size of the form.我的中间步骤结论是我需要保存表单的纯大小。 I will translate according to the scale.我会按比例翻译。 Then I guess, I can get a real size of the form.然后我想,我可以获得表格的真实大小。 I'm not really sure I will try and share what I find for letting someone out in the loop.我不确定我是否会尝试分享我发现的让某人参与其中的内容。

@Jimi and @Louis Go I hope that one day I can help you too. @Jimi 和 @Louis Go 我希望有一天我也能帮助你。 Thank you for helping me.感谢你们对我的帮助。

Jimi:吉米:

Make your application DpiAware if haven't.如果还没有,请让您的应用程序 DpiAware。 Start from here: How to configure an app to run correctly on a machine with a high DPI setting (eg 150%)?从这里开始: 如何配置应用程序以在具有高 DPI 设置(例如 150%)的机器上正确运行? , then take a look at the app.config settings and to High DPI support in Windows Forms (consider and test the PerMonitorV2 setup). ,然后查看 app.config 设置和Windows 窗体中的高 DPI 支持(考虑并测试PerMonitorV2设置)。 Take into consideration the Form's AutoScaleMode .考虑表单的AutoScaleMode See the difference between Dpi and Font .查看DpiFont之间的区别。

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

相关问题 在设计模式下控件大小较大时,Windows窗体将引发Argument异常 - Windows form throws Argument exception when the control size is larger in design mode Form.DesktopBounds.Width似乎偏离了10个像素。 如何确定正确的表格宽度? - Form.DesktopBounds.Width seems to be off by 10 pixels. How to determine correct form width? OnShareTarget在Windows10上激活 - OnShareTargetActivated on Windows10 缩放Windows窗体的大小及其控制 - Scale the size of windows form and it's control 任务保持Form实例打开? - Task keeping Form instance open? 关闭MessageBox但保持表单打开 - Closing a MessageBox but keeping Form Open 如果标签宽度不适合C#Windows窗体应用程序中的文本宽度,如何使标签中的文本像(选取框)一样移动? - How can i make the text in the label move like in (marquee) if the label width not fit the text width in C# windows form application? 我的窗口窗体按钮设置为宽度 0 时它应该是全宽 - My windows form button is set to width 0 when it should be full width 带有文本框的列表视图Windows10 - Listview with Textbox WIndows10 如何打印大于屏幕尺寸的Form或FlowLayoutPanel尺寸? - How can I size a Form or a FlowLayoutPanel for printing larger than the Screen size?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM