WinForms - 错误的表单大小 [英] WinForms - wrong form size

查看:30
本文介绍了WinForms - 错误的表单大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有以下代码:

    private void MainForm_Shown(object sender, EventArgs e)
    {
        RepositionForm();
    }

    private void RepositionForm()
    {
        Rectangle rect = Screen.PrimaryScreen.WorkingArea;
        this.Width = 100;
        this.Height = 117;
        this.TopMost = true;
        this.Left = rect.Width - this.Width - 1;
        this.Top = rect.Height - this.Height - 1;
    }

当我们从 Visual Studio 启动应用程序时 - 表单显示的大小正确:100x117.但是,当我们通过启动EXE文件启动项目时,表单大小为106x127.

When we launch the app from Visual Studio - the form is shown of correct size: 100x117. However, when we launch the project by launching EXE file, the form size is 106x127.

The MinimumSize, MaximumSize and Size properties are set to 100x117.
WindowsState = Minimized
ShowIcon = False
ShowInTaskbar = False
Topmost = True
MinimizeBox - False
MaximizeBox = False
FormBorderSize = FixedDialog
ControlBox = True

怎么会发生应用程序启动方式之间甚至存在差异的情况?

How can that happen that there's even a difference between how the app is launched?

谢谢

推荐答案

我冒昧地猜测问题出在 Windows 主题和/或桌面窗口管理器对您的操作系统版本不确定.

I'm going to hazard a guess that the problem is with the windows theme and/or the Desktop Window Manager not being deterministic for your OS version.

尝试将您的 Windows 主题设置为基本(桌面->个性化),然后重新运行您的测试.如果你得到不同的结果,你知道它归结于 Windows 而不是你的代码.

Try setting your Windows Theme to basic (Desktop->Personalise), then rerun you test. If you get different results, you know its down to Windows and not your code.

此外,您可能还想查看 Windows 框架的非客户区,看看它是否与操作系统/主题有所不同.

Also you you may want to check out the non-client area of the windows frame and see if that changes from OS/theme.

这篇关于WinForms - 错误的表单大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆