当前位置: 动力学知识库 > 问答 > 编程问答 >

c# 4.0 - Move child window in side parent window in wpf

问题描述:

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;

}

As you can see the code above written, but I am not able to restrict the window while moving

at the bottom and right of Desktop. Because I am not finding any attribute for that.

Like this.Right

or this.Bottom

Please suggest if Any one has implemented the same.

Thanks

Madhav

网友答案:

this.Right would be:

this.Left + this.Width

this.Bottom is:

this.Top + this.Height

So the lines of code that are equivalent to what you have written above, but for right and bottom would be:

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;
分享给朋友:
您可能感兴趣的文章:
随机阅读: