如何将winform调整到顶部而不是底部c#

时间:2013-11-20 20:59:05

标签: c# winforms resize

当我调整winform的大小时,它会扩展到底部而不是顶部。 如何将表单调整到顶部而不是底部?

谢谢!

1 个答案:

答案 0 :(得分:3)

如果您正在谈论在运行时更改表单的大小以使其向上扩展,那么您必须更改Location()属性以将其向上移动,以及更改高度:

        int ExpandUpwardsInPixels = 50;
        this.Location = new Point(this.Location.X, this.Location.Y - ExpandUpwardsInPixels); // move it up 
        this.Size = new Size(this.Size.Width, this.Size.Height + ExpandUpwardsInPixels); // increase the height 

另一种方法是修改Bounds()属性:

        int ExpandUpwardsInPixels = 50;
        Rectangle bnds = this.Bounds;
        bnds.Offset(0, -ExpandUpwardsInPixels);
        bnds.Height = bnds.Height + ExpandUpwardsInPixels;
        this.Bounds = bnds;