This documentation is archived and is not being maintained.

Control.SetBounds Method (Int32, Int32, Int32, Int32, BoundsSpecified)

.NET Framework 1.1

Sets the specified bounds of the control to the specified location and size.

[Visual Basic]
Overloads Public Sub SetBounds( _
   ByVal x As Integer, _
   ByVal y As Integer, _
   ByVal width As Integer, _
   ByVal height As Integer, _
   ByVal specified As BoundsSpecified _
)
[C#]
public void SetBounds(
 int x,
 int y,
 int width,
 int height,
 BoundsSpecified specified
);
[C++]
public: void SetBounds(
 int x,
 int y,
 int width,
 int height,
 BoundsSpecified specified
);
[JScript]
public function SetBounds(
   x : int,
 y : int,
 width : int,
 height : int,
 specified : BoundsSpecified
);

Parameters

x
The new Left property value of the control.
y
The new Top property value of the control.
width
The new Width property value of the control.
height
The new Height property value of the control.
specified
A bitwise combination of the BoundsSpecified values. For any parameter not specified, the current value will be used.

Example

[Visual Basic, C#, C++] The following example centers a Form on the screen in the Layout event. This will keep the form centered as the user resizes it. This example assumes you have created a Form control.

[Visual Basic] 

    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

[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);    
}

[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);    
    }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Control Class | Control Members | System.Windows.Forms Namespace | Control.SetBounds Overload List | Bounds | SetBoundsCore | Layout

Show: