Share via


Control.Location Properti

Definisi

Mendapatkan atau mengatur koordinat sudut kiri atas kontrol relatif terhadap sudut kiri atas kontainernya.

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

Nilai Properti

Point yang mewakili sudut kiri atas kontrol relatif terhadap sudut kiri atas kontainernya.

Contoh

Contoh kode berikut membuat GroupBox dan menetapkan beberapa properti umumnya. Contoh membuat TextBox dan mengaturnya Location dalam kotak grup. Selanjutnya, ini mengatur Text properti kotak grup, dan menambungkan kotak grup ke bagian atas formulir. Terakhir, ini menonaktifkan kotak grup dengan mengatur Enabled properti ke false, yang menyebabkan semua kontrol yang terkandung dalam kotak grup dinonaktifkan.

   // 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

Keterangan

Point Karena kelas adalah jenis nilai (Structure di Visual Basic, struct di Visual C#), kelas dikembalikan oleh nilai, yang berarti mengakses properti mengembalikan salinan titik kiri atas kontrol. Jadi, menyesuaikan X properti atau Y dari properti yang Point dikembalikan dari properti ini tidak akan memengaruhi Leftnilai properti , , RightTop, atau Bottom kontrol. Untuk menyesuaikan properti ini, atur setiap nilai properti satu per satu, atau atur Location properti dengan yang baru Point.

Control Jika adalah Form, Location nilai properti mewakili sudut kiri atas koordinat Form layar dalam.

Berlaku untuk

Lihat juga