Form.DesktopLocation 属性

获取或设置 Windows 桌面上窗体的位置。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Property DesktopLocation As Point
用法
Dim instance As Form
Dim value As Point

value = instance.DesktopLocation

instance.DesktopLocation = value
public Point DesktopLocation { get; set; }
public:
property Point DesktopLocation {
    Point get ();
    void set (Point value);
}
/** @property */
public Point get_DesktopLocation ()

/** @property */
public void set_DesktopLocation (Point value)
public function get DesktopLocation () : Point

public function set DesktopLocation (value : Point)

属性值

Point,表示桌面上窗体的位置。

备注

桌面坐标基于屏幕的工作区,该区域不包括任务栏。桌面的坐标系统基于像素。如果应用程序正在多监视器系统上运行,那么窗体的坐标就是合并后的桌面的坐标。

可使用此属性相对 Windows 桌面上的其他窗体和应用程序放置您的窗体。

如果在调用 Show 方法之前调用 SetDesktopLocation 方法,您的窗体将定位在它的默认位置,该位置由操作系统决定。有关窗口定位的更多信息,请参见 https://www.microsoft.com/china/msdn/library. 处 MSDN 库中的“Window Features”文档的“Window Size and Position”部分。

如果在调用 Show 之后调用 SetDesktopLocation,您的窗体将定位在您指定的位置。

示例

下面的代码示例设置窗体的位置,使窗体位于距桌面左边框 100 个像素、距桌面顶部 100 个像素的位置。此示例要求已在窗体类内定义了方法。

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
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:
   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.set_DesktopLocation(tempPoint);
} //MoveMyForm

平台

Windows 98、Windows 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

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

Form 类
Form 成员
System.Windows.Forms 命名空间
Form.DesktopBounds 属性