我们有以下代码:
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。
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 框架的非客户区,看看它是否因操作系统/主题而改变。
关于c# - WinForms - 表格大小错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15136564/