Control.Anchor Özellik
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Denetimin bağlı olduğu kapsayıcının kenarlarını alır veya ayarlar ve denetimin üst öğesiyle nasıl yeniden boyutlandırileceğini 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 ortak özelliklerinden bazılarını 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 TabStop true
olarak ayarlar ve özelliğini ayarlar TabIndex . Son olarak, düğmenin olayını işlemek Click için bir olay işleyicisi ekler. Bu örnek, adlı imageList1
bir ImageList öğesinin olmasını gerektirir.
// 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. Denetimi üst denetimine bağlama, üst denetim yeniden boyutlandırıldığında sabitlenmiş 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 Bottom
olarak ayarlanmış Top
bir Anchor Button değerine sahipsenizForm, Button değerinin değeri artırıldığında öğesinin üst ve alt kenarlarına sabitlenmiş mesafeyi Form Height Form korumak için uzatılır.
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 uygulamayı 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.