Export (0) Print
Expand All

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

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

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public void SetBounds (
	int x,
	int y,
	int width,
	int height,
	BoundsSpecified specified
)
public void SetBounds (
	int x, 
	int y, 
	int width, 
	int height, 
	BoundsSpecified specified
)
public function SetBounds (
	x : int, 
	y : int, 
	width : int, 
	height : int, 
	specified : BoundsSpecified
)
Not applicable.

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.

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.

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).get_Width() 
        / 2 - this.get_Width() / 2, Screen.GetBounds(this).get_Height() 
        / 2 - this.get_Height() / 2, this.get_Width(), this.get_Height(), 
        BoundsSpecified.Location);
} //MyForm_Layout

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft