How to: Set the Screen Location of Windows Forms
You can specify where a form is to be displayed on the computer screen by entering values in theproperty. This specifies the position, in pixels, of the top-left corner of the form. Also, you need to set the property to indicate the boundaries of the display area.
Keep in mind that screen size and resolution often vary depending on the user's system. Additionally, systems that have multiple monitors attached may have trouble recognizing the boundaries of the display area. These two situations will often cause a form's location to change unpredictably, despite the Location property setting. For this reason, the default setting for the StartPosition property for a Windows Application is, which tells the operating system to compute the best location for the form at startup, based on the current hardware. Another alternative is to set the StartPosition property to Center and then change the location of the form in code. See "To position forms programmatically" below for more information.
To position forms using the Properties window
In the Properties window, choose the form from the drop-down. Set the form's StartPosition property to.
Type the values for the Location property, separated by a comma, to position the form, where the first number (X) is the distance from the left border of the display area and second number (Y) is the distance from the upper border of the display area.
Expand the Location property to enter theand property values individually.
To position forms programmatically
Define the location of a form at run time by setting the Location property of the form to a, as shown in the following example:
Change the X coordinate or Y coordinate of the form's location using theproperty (for the X coordinate) and the property (for the Y coordinate). The following example adjusts the form's X coordinate to the 300 pixel point:
To change form position programmatically by increments
Increment the X coordinate of the form using the Left property. The following example adjusts the form's X coordinate by 200 pixels:
Use the Location property to set a Windows Form's X and Y positions simultaneously. To set them individually, use the form's Left (X) or Top (Y) property. Do not try to implicitly set the X and Y coordinates of the Point structure that represents the form's location, because this contains a copy of the form's coordinates.
In lieu of using the Location property, theproperty can be used to set the location of your form. This property sets the location of your form relative to the taskbar and is useful if the taskbar has been docked to the top or left of the user's monitor. Docking the taskbar in this fashion obscures the desktop coordinates (0,0). A form with the DesktopLocation property set to (0, 0) always appears in the upper left corner of the primary monitor, but not behind the taskbar.
To set the Desktop Location property programmatically
Set the DesktopLocation property as you would any other property. The following example establishes a new location for an Accounts form.
The DesktopLocation property does not appear in the Properties window and can only be set in code.