Control.Location 屬性

定義

取得或設定對應至控制項容器左上角之控制項左上角的座標。

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

屬性值

Point,表示對應至控制項容器左上角之控制項的左上角。

範例

下列程式碼範例會建立 , GroupBox 並設定其一些通用屬性。 此範例會建立 , TextBox 並在群組方塊中設定其 Location 。 接下來,它會設定 Text 群組方塊的 屬性,並將群組方塊停駐到表單頂端。 最後,它會將 屬性 false 設定 Enabled 為 來停用群組方塊,這會停用群組方塊中包含的所有控制項。

C#
// 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 是 Visual Basic 中的實數值型別 (Structurestruct 在 Visual C#) 中,它會以值傳回,這表示存取 屬性會傳回控制項左上角的複本。 因此,調整 X 從這個屬性傳回之 的 PointY 屬性,不會影響 控制項的 LeftRightTopBottom 屬性值。 若要個別調整這些屬性,請個別設定每個屬性值,或使用新的 Point 來設定 Location 屬性。

Control如果 是 FormLocation 屬性值代表螢幕座標中的 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

另請參閱