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 值的位元組合。 任何未指定的參數會使用目前的值。

範例

下列程式碼範例會在 事件中的 畫面上置 FormLayout 。 這會讓表單保持置中,因為使用者調整表單大小。 此範例會要求您已建立 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