Language

Control.Location プロパティ

定義

コンテナーの左上隅を基準としたコントロールの左上隅の座標を取得または設定します。

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 プロパティを設定し、グループ ボックスをフォームの上部にドッキングします。 最後に、 Enabled プロパティを false に設定することで、グループ ボックスを無効にします。これにより、グループ ボックスに含まれるすべてのコントロールが無効になります。

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

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

適用対象

こちらもご覧ください