英語で読む

次の方法で共有


Form.SetDesktopLocation(Int32, Int32) メソッド

定義

フォームの位置をデスクトップ座標で設定します。

C#
public void SetDesktopLocation(int x, int y);

パラメーター

x
Int32

フォームの位置の x 座標。

y
Int32

フォームの位置の y 座標。

次の例では、 メンバーLoad、および Activate メンバーの使用方法をSetDesktopLocation示します。 この例を実行するには、 という名前のボタンButton1と と という Form1 2 つのLabelコントロールを含む というフォームに次のコードをLabel1Label2貼り付けます。

C#
static int x = 200;
static int y = 200;

private void Button1_Click(System.Object sender, 
    System.EventArgs e)
{
    // Create a new Form1 and set its Visible property to true.
    Form1 form2 = new Form1();
    form2.Visible = true;

    // Set the new form's desktop location so it  
    // appears below and to the right of the current form.
    form2.SetDesktopLocation(x, y);
    x += 30;
    y += 30;

    // Keep the current form active by calling the Activate
    // method.
    this.Activate();
    this.Button1.Enabled = false;
}

// Updates the label text to reflect the current values of x 
// and y, which was were incremented in the Button1 control's 
// click event.
private void Form1_Activated(object sender, System.EventArgs e)
{
    Label1.Text = "x: "+x+" y: "+y;
    Label2.Text = "Number of forms currently open: "+count;
}

static int count = 0;

private void Form1_Closed(object sender, System.EventArgs e)
{
    count -= 1;
}

private void Form1_Load(object sender, System.EventArgs e)
{
    count += 1;
}

注釈

デスクトップ座標は、タスク バーを除外する画面の作業領域に基づいています。 このメソッドを使用して、フォームをデスクトップに配置できます。 デスクトップ座標はフォームの作業領域に基づいているため、このメソッドを使用して、フォームがデスクトップに完全に表示されるようにすることができます。 このメソッドは、主に最上位のフォームに使用することを目的としています。メソッドを LayoutMdi 使用して、複数ドキュメント インターフェイス (MDI) 子フォームを配置します。

適用対象

製品 バージョン
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

こちらもご覧ください