Form.DesktopLocation 属性

定义

获取或设置 Windows 桌面上窗体的位置。Gets or sets the location of the form on the Windows desktop.

public:
 property System::Drawing::Point DesktopLocation { System::Drawing::Point get(); void set(System::Drawing::Point value); };
[System.ComponentModel.Browsable(false)]
public System.Drawing.Point DesktopLocation { get; set; }
member this.DesktopLocation : System.Drawing.Point with get, set
Public Property DesktopLocation As Point

属性值

Point,表示桌面上窗体的位置。A Point that represents the location of the form on the desktop.

属性

示例

下面的示例设置窗体的位置,以使窗体在桌面的左边缘和距桌面顶部100像素的位置定位为100像素。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 requires that method has been defined within a form class.

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

注解

桌面坐标基于屏幕上的工作区域,其中不包括任务栏。Desktop coordinates are based on the working area of the screen, which excludes the taskbar. 桌面的坐标系统是基于像素的。The coordinate system of the desktop is pixel based. 如果你的应用程序在 multimonitor 系统上运行,则该窗体的坐标是组合桌面的坐标。If your application is running on a multimonitor system, the coordinates of the form are the coordinates for the combined desktop.

您可以使用此属性来相对于 Windows 桌面上的其他窗体和应用程序定位窗体。You can use this property to position your form relative to other forms and applications on the Windows desktop.

如果在调用 Show 方法之前调用 SetDesktopLocation 方法,则您的窗体将定位在其默认位置,该位置由操作系统确定。If you call the SetDesktopLocation method before calling the Show method, your form will be positioned at its default location, which is determined by the operating system. 有关窗口定位的详细信息,请参阅 MSDN library 中的 "窗口大小和位置" 部分,网址为 https://msdn.microsoft.com/library。For more information about window positioning, see the "Window Size and Position" section of the "Window Features" document in the MSDN library at https://msdn.microsoft.com/library.

如果调用 Show 后调用 SetDesktopLocation,则窗体将定位在指定的位置。If you call SetDesktopLocation after calling Show, your form will be positioned at the location you specified.

适用于

另请参阅