This documentation is archived and is not being maintained.

Form.DesktopLocation Property

Gets or sets the location of the form on the Windows desktop.

[Visual Basic]
Public Property DesktopLocation As Point
[C#]
public Point DesktopLocation {get; set;}
[C++]
public: __property Point get_DesktopLocation();
public: __property void set_DesktopLocation(Point);
[JScript]
public function get DesktopLocation() : Point;
public function set DesktopLocation(Point);

Property Value

A Point that represents the location of the form on the desktop.

Remarks

Desktop coordinates are based on the working area of the screen, which excludes the taskbar. The coordinate system of the desktop is pixel based. If your application is running on a multimonitor system, the coordinates of the form are the coordinates for the combined desktop.

You can use this property to position your form relative to other forms and applications on the Windows desktop.

If you call the SetDesktopLocation method before calling the System.Windows.Forms.Form.Show method, your form will be positioned at its default location, which is determined by the operating system. For more information about window positioning, see the "Window Size and Position" section of the "Window Features" document in the MSDN library at http://msdn.microsoft.com/library .

If you call SetDesktopLocation after calling System.Windows.Forms.Form.Show, your form will be positioned at the location you specified.

Example

[Visual Basic, C#, C++] The following example sets the position of a form so that the form is positioned 100 pixels from the left border of the desktop and 100 pixels from the top of the desktop. This example assumes method has been defined within a form class.

[Visual Basic] 
Public Sub MoveMyForm()
    ' Create a Point object that will be used as the location of the form.
    Dim tempPoint As New Point(100, 100)
    ' Set the location of the form using the Point object.
    DesktopLocation = tempPoint
End Sub 'MoveMyForm

[C#] 
public void MoveMyForm()
 {
    // Create a Point object that will be used as the location of the form.
    Point tempPoint = new Point(100,100);
    // Set the location of the form using the Point object.
    this.DesktopLocation = tempPoint;
 }
   

[C++] 
public:
void MoveMyForm()
 {
    // Create a Point object that will be used as the location of the form.
    Point tempPoint = Point(100,100);
    // Set the location of the form using the Point object.
    this->DesktopLocation = tempPoint;
 }
   

[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

Form Class | Form Members | System.Windows.Forms Namespace | DesktopBounds

Show: