Control.SetBounds 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
設定控制項的範圍。
多載
SetBounds(Int32, Int32, Int32, Int32) |
將控制項的範圍設定為指定的位置和大小。 |
SetBounds(Int32, Int32, Int32, Int32, BoundsSpecified) |
將控制項的指定範圍設定為指定的位置和大小。 |
SetBounds(Int32, Int32, Int32, Int32)
將控制項的範圍設定為指定的位置和大小。
public:
void SetBounds(int x, int y, int width, int height);
public void SetBounds (int x, int y, int width, int height);
member this.SetBounds : int * int * int * int -> unit
Public Sub SetBounds (x As Integer, y As Integer, width As Integer, height As Integer)
參數
另請參閱
適用於
SetBounds(Int32, Int32, Int32, Int32, BoundsSpecified)
將控制項的指定範圍設定為指定的位置和大小。
public:
void SetBounds(int x, int y, int width, int height, System::Windows::Forms::BoundsSpecified specified);
public void SetBounds (int x, int y, int width, int height, System.Windows.Forms.BoundsSpecified specified);
member this.SetBounds : int * int * int * int * System.Windows.Forms.BoundsSpecified -> unit
Public Sub SetBounds (x As Integer, y As Integer, width As Integer, height As Integer, specified As BoundsSpecified)
參數
- specified
- BoundsSpecified
BoundsSpecified 值的位元組合。 任何未指定的參數會使用目前的值。
範例
下列程式碼範例會在 事件中的 畫面上置 Form 中 Layout 。 這會讓表單保持置中,因為使用者調整表單大小。 此範例會要求您已建立 Form 控制項。
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 );
}
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);
}
Private Sub MyForm_Layout(ByVal sender As Object, _
ByVal e As System.Windows.Forms.LayoutEventArgs) Handles MyBase.Layout
' Center the Form on the user's screen everytime it requires a Layout.
Me.SetBounds((System.Windows.Forms.Screen.GetBounds(Me).Width / 2) - (Me.Width / 2), _
(System.Windows.Forms.Screen.GetBounds(Me).Height / 2) - (Me.Height / 2), _
Me.Width, Me.Height, System.Windows.Forms.BoundsSpecified.Location)
End Sub