Control.Location 属性
获取或设置该控件的左上角相对于其容器的左上角的坐标。
**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)
语法
声明
<LocalizableAttribute(True)> _
Public Property Location As Point
用法
Dim instance As Control
Dim value As Point
value = instance.Location
instance.Location = value
[LocalizableAttribute(true)]
public Point Location { get; set; }
[LocalizableAttribute(true)]
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,它表示控件的左上角相对于其容器的左上角。
备注
由于 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 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:2.0、1.0
请参见
参考
Control 类
Control 成员
System.Windows.Forms 命名空间
Form
ContainerControl 类