Control.Anchor Özellik

Tanım

Denetimin bağlı olduğu kapsayıcının kenarlarını alır veya ayarlar ve denetimin üst öğesiyle nasıl yeniden boyutlandırıldığını belirler.

public:
 virtual property System::Windows::Forms::AnchorStyles Anchor { System::Windows::Forms::AnchorStyles get(); void set(System::Windows::Forms::AnchorStyles value); };
public virtual System.Windows.Forms.AnchorStyles Anchor { get; set; }
member this.Anchor : System.Windows.Forms.AnchorStyles with get, set
Public Overridable Property Anchor As AnchorStyles

Özellik Değeri

Değerlerin bit düzeyinde birleşimi AnchorStyles . Varsayılan değer ve Left'dirTop.

Örnekler

Aşağıdaki kod örneği forma bir Button ekler ve bazı ortak özelliklerini ayarlar. Örnek düğmeyi formun sağ alt köşesine sabitler, böylece form yeniden boyutlandırılırken göreli konumunu korur. Ardından düğmesini ayarlar BackgroundImage ve düğmeyi ile aynı boyuta Imageyeniden boyutlandırılır. Örnek daha sonra öğesini TabStoptrue olarak ayarlar ve özelliğini ayarlar TabIndex . Son olarak, düğmenin olayını işlemek Click için bir olay işleyicisi ekler. Bu örnekte adlı imageList1bir ImageList olması gerekir.

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

Açıklamalar

Anchor Üst denetimi yeniden boyutlandırılırken denetimin otomatik olarak nasıl yeniden boyutlandırılacağını tanımlamak için özelliğini kullanın. Bir denetimi üst denetimine tutturmak, üst denetim yeniden boyutlandırıldığında bağlantılı kenarların üst denetimin kenarlarına göre aynı konumda kalmasını sağlar.

Denetimi kapsayıcısının bir veya daha fazla kenarına sabitleyebilirsiniz. Örneğin, özellik değeri ve Bottomolarak ayarlanmış Top olan Anchor bir Button değerine sahipsenizForm, Button öğesinin değeri artırıldığında üst ve alt kenarlarına FormHeightForm sabitlenmiş uzaklığı korumak için esnetilir.

Not

Anchor ve Dock özellikleri birbirini dışlar. Aynı anda yalnızca bir küme ayarlanabilir ve son küme önceliklidir.

Devralanlara Notlar

Türetilmiş bir sınıfta özelliğini geçersiz kıldığınızda Anchor temel uygulamanın kapsamını genişletmek için temel sınıfın Anchor özelliğini kullanın. Aksi takdirde, tüm uygulamayı sağlamanız gerekir. Özelliğin get hem hem set de erişimcilerini Anchor geçersiz kılmanız gerekmez; gerekirse yalnızca birini geçersiz kılabilirsiniz.

Şunlara uygulanır

Ayrıca bkz.