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启动应用程序时 – 表单显示正确的大小:100×117。 但是,当我们通过启动EXE文件启动项目时,表单大小为106×127。

 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 

怎么会发生应用程序如何推出之间的差异呢?

谢谢

我将冒险猜测问题是Windows主题和/或桌面窗口管理器不是您的操作系统版本的确定性。

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

您也可以查看Windows框架的非客户区域,看看是否从OS /主题更改。