Export (0) Print
Expand All
Expand Minimize

Form.SetDesktopBounds Method

Sets the bounds of the form in desktop coordinates.

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

public void SetDesktopBounds (
	int x,
	int y,
	int width,
	int height
)
public void SetDesktopBounds (
	int x, 
	int y, 
	int width, 
	int height
)
public function SetDesktopBounds (
	x : int, 
	y : int, 
	width : int, 
	height : int
)
Not applicable.

Parameters

x

The x-coordinate of the form's location.

y

The y-coordinate of the form's location.

width

The width of the form.

height

The height of the form.

Desktop coordinates are based on the working area of the screen, which excludes the taskbar. You can use this method to set the position and size of your form on the desktop. Since desktop coordinates are based on the working area of the form, you can use this method to ensure that your form is completely visible on the desktop.

The following code example demonstrates using the SetDesktopBounds method. To run this example, paste the following code in a form that contains a button named Button2. Ensure all events are associated with their event handlers.

private void Button2_Click(System.Object sender, System.EventArgs e)
{
    
    for(int i = 0; i <= 20; i++)
    {
        // With each loop through the code, the form's 
        // desktop location is adjusted right and down
        //  by 10 pixels and its height and width are each
        // decreased by 10 pixels. 
        this.SetDesktopBounds(this.Location.X+10, 
            this.Location.Y+10, this.Width-10, this.Height-10);

        // Call Sleep to show the form gradually shrinking.
        System.Threading.Thread.Sleep(50);
    }
}

private void button2_Click(Object sender, System.EventArgs e)
{
    for (int i = 0; i <= 20; i++) {
        // With each loop through the code, the form's 
        // desktop location is adjusted right and down
        // by 10 pixels and its height and width are each
        // decreased by 10 pixels. 
        this.SetDesktopBounds(this.get_Location().get_X() + 10, 
            this.get_Location().get_Y() + 10, this.get_Width() - 10, 
            this.get_Height() - 10);
        // Call Sleep to show the form gradually shrinking.
        System.Threading.Thread.Sleep(50);
    }
} //button2_Click

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:
© 2015 Microsoft