Control.Location プロパティ
この記事の内容
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
コンテナーの左上隅に対する相対座標として、コントロールの左上隅の座標を取得または設定します。
public:
property System::Drawing::Point Location { System::Drawing::Point get(); void set(System::Drawing::Point value); };
public System.Drawing.Point Location { get; set; }
member this.Location : System.Drawing.Point with get, set
Public Property Location As Point
コントロールの左上隅をコンテナーの左上隅に対して相対的に表す 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 = gcnew GroupBox;
TextBox^ textBox1 = gcnew TextBox;
textBox1->Location = 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 );
}
// 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);
}
' Add a GroupBox to a form and set some of its common properties.
Private Sub AddMyGroupBox()
' Create a GroupBox and add a TextBox to it.
Dim groupBox1 As New GroupBox()
Dim textBox1 As 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.
Me.Controls.Add(groupBox1)
End Sub
クラスは値型 Point (Structure
Visual Basic では Visual C# では ) であるため、 struct
値によって返されます。つまり、 プロパティにアクセスすると、コントロールの左上のポイントのコピーが返されます。 そのため、このプロパティから返される または Y プロパティをPoint調整Xすると、コントロールの Left、Right、Topまたは 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 |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。