Control.SetBounds Method

Definition

Sets the bounds of the control.

Overloads

SetBounds(Int32, Int32, Int32, Int32)

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

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

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

SetBounds(Int32, Int32, Int32, Int32)

Source:
Control.cs
Source:
Control.cs
Source:
Control.cs

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

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

Parameters

x
Int32

The new Left property value of the control.

y
Int32

The new Top property value of the control.

width
Int32

The new Width property value of the control.

height
Int32

The new Height property value of the control.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.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)

Source:
Control.cs
Source:
Control.cs
Source:
Control.cs

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

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

Parameters

x
Int32

The new Left property value of the control.

y
Int32

The new Top property value of the control.

width
Int32

The new Width property value of the control.

height
Int32

The new Height property value of the control.

specified
BoundsSpecified

A bitwise combination of the BoundsSpecified values. For any parameter not specified, the current value will be used.

Examples

The following code example centers a Form on the screen in the Layout event. This will keep the form centered as the user resizes it. This example requires that you have created a Form control.

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

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.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