次の方法で共有


Form.DesktopLocation プロパティ

Windows デスクトップ上のフォームの位置を取得または設定します。

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

プロパティ値

デスクトップ上のフォームの位置を表す Point

解説

デスクトップ座標は、タスクバーを除外した画面の作業領域に基づきます。デスクトップの座標系は、ピクセル単位で表されます。アプリケーションが複数モニタ システムで実行されている場合、フォームの座標は、組み合わされたデスクトップの座標になります。

このプロパティを使用すると、Windows デスクトップ上の他のフォームやアプリケーションに合わせてフォームの位置を設定できます。

SetDesktopLocation メソッドを呼び出してから System.Windows.Forms.Form.Show メソッドを呼び出すと、既定の位置にフォームが配置されます。この位置はオペレーティング システムによって決まります。ウィンドウの位置の詳細については、MSDN ライブラリ (https://msdn.microsoft.com/library) で「Window Features」の「Window Size and Position」を参照してください。

System.Windows.Forms.Form.Show を呼び出してから SetDesktopLocation を呼び出すと、指定した位置にフォームが配置されます。

使用例

[Visual Basic, C#, C++] デスクトップの左端から 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

[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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

Form クラス | Form メンバ | System.Windows.Forms 名前空間 | DesktopBounds