Control.SetBounds 方法

定义

设置控件的边界。

重载

SetBounds(Int32, Int32, Int32, Int32)

将控件的边界设置为指定位置和大小。

SetBounds(Int32, Int32, Int32, Int32, BoundsSpecified)

将控件的指定边界设置为指定位置和大小。

SetBounds(Int32, Int32, Int32, Int32)

将控件的边界设置为指定位置和大小。

C#
public void SetBounds (int x, int y, int width, int height);

参数

x
Int32

控件的新 Left 属性值。

y
Int32

控件的新 Top 属性值。

width
Int32

控件的新 Width 属性值。

height
Int32

控件的新 Height 属性值。

另请参阅

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

SetBounds(Int32, Int32, Int32, Int32, BoundsSpecified)

将控件的指定边界设置为指定位置和大小。

C#
public void SetBounds (int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified);

参数

x
Int32

控件的新 Left 属性值。

y
Int32

控件的新 Top 属性值。

width
Int32

控件的新 Width 属性值。

height
Int32

控件的新 Height 属性值。

specified
BoundsSpecified

BoundsSpecified 值的按位组合。 对于任何未指定的参数,将使用当前值。

示例

下面的代码示例在 Layout 事件中在屏幕上居中居中Form。 这将在用户调整窗体大小时保持窗体居中。 此示例要求你已创建控件 Form

C#
private void MyForm_Layout(object sender, System.Windows.Forms.LayoutEventArgs e)
{
   // Center the Form on the user's screen everytime it requires a Layout.
   this.SetBounds((Screen.GetBounds(this).Width/2) - (this.Width/2),
       (Screen.GetBounds(this).Height/2) - (this.Height/2),
       this.Width, this.Height, BoundsSpecified.Location);	
}

另请参阅

适用于

.NET Framework 4.8.1 和其他版本
产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9