0
private void Window_LocationChanged(object sender, EventArgs e)
{

    if (this.Left < this.Owner.Left)
        this.Left = this.Owner.Left;

    if (this.Top < this.Owner.Top)
        this.Top = this.Owner.Top;

}

如您所见,上面编写的代码,但我无法在桌面的底部和右侧移动时限制窗口。因为我没有找到任何属性。

Like this.Right or this.Bottom

请建议是否有人实施了相同的。

谢谢马达夫

4

1 回答 1

0

this.Right 将是:

this.Left + this.Width

this.Bottom 是:

this.Top + this.Height

因此,与您在上面编写的代码行等效的代码行,但右侧和底部将是:

if (this.Left + this.Width > this.Owner.Left + this.Owner.Width)
    this.Left = this.Owner.Left + this.Owner.Width - this.Width;

if (this.Top + this.Height > this.Owner.Top + this.Owner.Height)
    this.Top = this.Owner.Top + this.Owner.Height - this.Height;
于 2012-11-28T11:55:24.603 回答