在wpf中的子父窗口中移动子窗口

时间:2012-11-28 11:44:53

标签: wpf c#-4.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;

}

正如您可以看到上面编写的代码,但我无法在移动时限制窗口 在桌面的右下角。因为我没有找到任何属性。

喜欢这个。对       或者.Bottom

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

由于 马达夫

1 个答案:

答案 0 :(得分: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;