我有一个正在进行的项目,为此项目我需要防止 从窗口离开屏幕边界。
我想出了办法,但窗口“滞后”或“跳跃”,我不希望发生这种情况。
我当前的代码:
private void Form1_Move(object sender, EventArgs e)
{
if (this.Top < 0)
{
this.Top = 0;
}
if (this.Left < 0)
{
this.Left = 0;
}
if (this.Left + this.Width > Screen.PrimaryScreen.WorkingArea.Size.Width)
{
this.Left = Screen.PrimaryScreen.WorkingArea.Size.Width - this.Width;
}
if (this.Top + this.Height > Screen.PrimaryScreen.WorkingArea.Size.Height)
{
this.Top = Screen.PrimaryScreen.WorkingArea.Size.Height - this.Height;
}
}
感谢所有帮助!