Control.Location プロパティ

定義

コンテナーの左上隅に対する相対座標として、コントロールの左上隅の座標を取得または設定します。

public System.Drawing.Point Location { get; set; }

プロパティ値

コントロールの左上隅をコンテナーの左上隅に対して相対的に表す Point

次のコード例では、 を GroupBox 作成し、その共通プロパティの一部を設定します。 この例では、 を TextBox 作成し、グループ ボックス内で を Location 設定します。 次に、グループ ボックスの Text プロパティを設定し、グループ ボックスをフォームの上部にドッキングします。 最後に、 プロパティを にfalse設定してグループ ボックスをEnabled無効にします。これにより、グループ ボックスに含まれるすべてのコントロールが無効になります。

// Add a GroupBox to a form and set some of its common properties.
private void AddMyGroupBox()
{
   // Create a GroupBox and add a TextBox to it.
   GroupBox groupBox1 = new GroupBox();
   TextBox textBox1 = new TextBox();
   textBox1.Location = new Point(15, 15);
   groupBox1.Controls.Add(textBox1);

   // Set the Text and Dock properties of the GroupBox.
   groupBox1.Text = "MyGroupBox";
   groupBox1.Dock = DockStyle.Top;

   // Disable the GroupBox (which disables all its child controls)
   groupBox1.Enabled = false;

   // Add the Groupbox to the form.
   this.Controls.Add(groupBox1);
}

注釈

クラスは値型 Point (Structure Visual Basic では Visual C# では ) であるため、 struct 値によって返されます。つまり、 プロパティにアクセスすると、コントロールの左上のポイントのコピーが返されます。 そのため、このプロパティから返される または Y プロパティをPoint調整Xすると、コントロールの LeftRightTopまたは Bottom プロパティの値には影響しません。 これらのプロパティを調整するには、各プロパティ値を個別に設定するか、新しい Pointを使用して Location プロパティを設定します。

Controlが のForm場合、プロパティ値Locationは 画面座標内の の左上隅をForm表します。

適用対象

製品 バージョン
.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

こちらもご覧ください