更新 : 2007 年 11 月
コンテナの左上隅に対する相対座標として、コントロールの左上隅の座標を取得または設定します。
名前空間 :
System.Windows.Forms アセンブリ :
System.Windows.Forms (System.Windows.Forms.dll 内)
Public Property Location As Point
Dim instance As Control
Dim value As Point
value = instance.Location
instance.Location = value
public Point Location { get; set; }
public:
property Point Location {
Point get ();
void set (Point value);
}
/** @property */
public Point get_Location()
/** @property */
public void set_Location(Point value)
public function get Location () : Point
public function set Location (value : Point)
Point クラスは値型 (Visual Basic では Structure、Visual C# では struct) であるため、値で返されます。つまり、このプロパティにアクセスすると、コントロールの左上隅のコピーが返されます。したがって、このプロパティから返された Point の X プロパティまたは Y プロパティを調整しても、コントロールの Left、Right、Top、または Bottom の各プロパティ値に影響はありません。これらのプロパティを調整するには、各プロパティ値を個別に設定するか、または新しい Point で Location プロパティを設定します。
Control が Form の場合、Location プロパティ値は Form の左上隅の画面座標を表します。
GroupBox を作成して、共通プロパティの一部を設定するコード例を次に示します。この例では、TextBox を作成し、グループ ボックス内での Location を設定しています。次に、グループ ボックスの Text プロパティを設定して、グループ ボックスをフォームの上部にドッキングします。最後に、Enabled プロパティを false に設定してグループを無効にします。これにより、グループ ボックスに含まれるすべてのコントロールが無効になります。
' 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
// 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:
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.set_Location(new Point(15, 15));
groupBox1.get_Controls().Add(textBox1);
// Set the Text and Dock properties of the GroupBox.
groupBox1.set_Text("MyGroupBox");
groupBox1.set_Dock(DockStyle.Top);
// Disable the GroupBox (which disables all its child controls)
groupBox1.set_Enabled(false);
// Add the Groupbox to the form.
this.get_Controls().Add(groupBox1);
} //AddMyGroupBox
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC
.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。
.NET Framework
サポート対象 : 3.5、3.0、2.0、1.1、1.0
.NET Compact Framework
サポート対象 : 3.5、2.0、1.0
参照
その他の技術情報