AnchorStyles Enum

Definisi

Menentukan bagaimana jangkar kontrol ke tepi kontainernya.

Enumerasi ini mendukung kombinasi bitwise dari nilai yang termasuk di dalamnya.

public enum class AnchorStyles
[System.Flags]
public enum AnchorStyles
[<System.Flags>]
type AnchorStyles = 
Public Enum AnchorStyles
Warisan
AnchorStyles
Atribut

Bidang

Bottom 2

Kontrol dilabuhkan ke tepi bawah kontainernya.

Left 4

Kontrol dilabuhkan ke tepi kiri kontainernya.

None 0

Kontrol tidak berlabuh ke tepi kontainernya.

Right 8

Kontrol dilabuhkan ke tepi kanan kontainernya.

Top 1

Kontrol berlabuh ke tepi atas kontainernya.

Contoh

Contoh berikut menambahkan Button ke formulir dan mengatur beberapa properti umumnya. Contoh jangkar tombol ke sudut kanan bawah formulir sehingga mempertahankan posisi relatifnya saat formulir diubah ukurannya. Selanjutnya mengatur BackgroundImage dan mengubah ukuran tombol ke ukuran yang sama dengan Image. Contoh kemudian mengatur ke TabStoptrue dan mengatur TabIndex properti . Terakhir, ini menambahkan penanganan aktivitas untuk menangani Click peristiwa tombol. Contoh ini mengasumsikan Anda memiliki nama ImageListimageList1.

   // Add a button to a form and set some of its common properties.
private:
   void AddMyButton()
   {
      // Create a button and add it to the form.
      Button^ button1 = gcnew Button;

      // Anchor the button to the bottom right corner of the form
      button1->Anchor = static_cast<AnchorStyles>(AnchorStyles::Bottom | AnchorStyles::Right);

      // Assign a background image.
      button1->BackgroundImage = imageList1->Images[ 0 ];

      // Specify the layout style of the background image. Tile is the default.
      button1->BackgroundImageLayout = ImageLayout::Center;

      // Make the button the same size as the image.
      button1->Size = button1->BackgroundImage->Size;

      // Set the button's TabIndex and TabStop properties.
      button1->TabIndex = 1;
      button1->TabStop = true;

      // Add a delegate to handle the Click event.
      button1->Click += gcnew System::EventHandler( this, &Form1::button1_Click );

      // Add the button to the form.
      this->Controls->Add( button1 );
   }
// Add a button to a form and set some of its common properties.
private void AddMyButton()
{
   // Create a button and add it to the form.
   Button button1 = new Button();

   // Anchor the button to the bottom right corner of the form
   button1.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);

   // Assign a background image.
   button1.BackgroundImage = imageList1.Images[0];

   // Specify the layout style of the background image. Tile is the default.
   button1.BackgroundImageLayout = ImageLayout.Center;
   
   // Make the button the same size as the image.
   button1.Size = button1.BackgroundImage.Size;

   // Set the button's TabIndex and TabStop properties.
   button1.TabIndex = 1;
   button1.TabStop = true;

   // Add a delegate to handle the Click event.
   button1.Click += new System.EventHandler(this.button1_Click);

   // Add the button to the form.
   this.Controls.Add(button1);
}
' Add a button to a form and set some of its common properties.
Private Sub AddMyButton()
   ' Create a button and add it to the form.
   Dim button1 As New Button()
   
   ' Anchor the button to the bottom right corner of the form
   button1.Anchor = AnchorStyles.Bottom Or AnchorStyles.Right
   
   ' Assign a background image.
   button1.BackgroundImage = imageList1.Images(0)

   ' Specify the layout style of the background image. Tile is the default.
   button1.BackgroundImageLayout = ImageLayout.Center
   
   ' Make the button the same size as the image.
   button1.Size = button1.BackgroundImage.Size
   
   ' Set the button's TabIndex and TabStop properties.
   button1.TabIndex = 1
   button1.TabStop = True

   ' Add a delegate to handle the Click event.
   AddHandler button1.Click, AddressOf Me.button1_Click
   
   ' Add the button to the form.
   Me.Controls.Add(button1)
End Sub

Keterangan

Ketika kontrol berlabuh ke tepi kontainernya, jarak antara kontrol dan tepi yang ditentukan tetap konstan saat kontainer mengubah ukuran. Misalnya, jika kontrol dilabuhkan ke tepi kanan kontainernya, jarak antara tepi kanan kontrol dan tepi kanan kontainer tetap konstan saat kontainer mengubah ukuran. Kontrol dapat dilabuhkan ke kombinasi tepi kontrol apa pun. Jika kontrol berlabuh ke tepi kontainernya yang berlawanan (misalnya, ke atas dan bawah), kontrol akan mengubah ukuran saat kontainer mengubah ukuran. Jika kontrol mengatur propertinya Anchor ke Tidak Ada, kontrol akan memindahkan setengah dari jarak kontainer kontrol diubah ukurannya. Misalnya, jika Button propertinya diatur ke Tidak Ada dan Form bahwa kontrol berada diubah ukurannya Anchor sebesar 20 piksel di kedua arah, tombol akan dipindahkan 10 piksel ke kedua arah.

Berlaku untuk

Lihat juga