private Point AdjustPosition(Point point, int height, int width)
{
Point pTemp = point;
if (point.X + width > Screen.PrimaryScreen.WorkingArea.Width) pTemp.X = Screen.PrimaryScreen.WorkingArea.Width - width;
if (point.Y + height > Screen.PrimaryScreen.WorkingArea.Height) pTemp.Y = Screen.PrimaryScreen.WorkingArea.Height - height;
return pTemp;
}
private void 窗体名称_LocationChanged(object sender, EventArgs e)
{
p = this.Location;
this.PointToScreen(p);
this.Location = AdjustPosition(p, this.Height, this.Width);
}
本文介绍了一个用于调整窗口位置的方法,确保窗口不会超出屏幕边界。通过计算并调整窗口的坐标,使得即使在改变窗口位置时,其也不会超出可用屏幕区域。

被折叠的 条评论
为什么被折叠?



