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 -> unitPublic 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 -> unitPublic Sub SetBounds (x As Integer, y As Integer, width As Integer, height As Integer, specified As BoundsSpecified)参数
- specified
- BoundsSpecified
BoundsSpecified 值的按位组合。 对于任何未指定的参数,将使用当前值。
示例
下面的代码示例在 Layout 事件中在屏幕上居中居中Form。 这将在用户调整窗体大小时保持窗体居中。 此示例要求你已创建控件 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