共用方式為


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

Control如果 是 FormLocation 屬性值代表螢幕座標中的 Form 左上角。

適用於

另請參閱