我有一个Windows窗体应用程序,我使用以下代码在启动时将其停靠在屏幕的右下方:
protected override void OnLoad(EventArgs e)
{
var s = Screen.FromPoint(this.Location);
this.Location = new Point(s.WorkingArea.Right - this.Width,
s.WorkingArea.Height - this.Height);
base.OnLoad(e);
}
当我处于Visual Studio调试模式时,这就像魅力一样。当我构建一个安装程序并安装应用程序(在相同的开发框上)并运行它时,坐标略有不同,并且表单没有完美地停靠在角落里。所以我把它放在OnLoad中:
MessageBox.Show(this.Location.X + "x" + this.Location.Y);
在开发模式下,它显示 1355x720 ,但在安装时显示 1365x730
为什么要分心?显然我可以减去10来使我的代码工作,但我想解释一下这种行为。
更新
Screen.WorkingArea
)。在开发模式下,表单大小显示为245x140但在我安装时显示为235x130 TopMost
设置为True