AnchorStyles Enumeráció
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Meghatározza, hogy egy vezérlő hogyan rögzíti a tároló széleit.
Ez a felsorolás támogatja a tagértékek bitenkénti kombinációját.
public enum class AnchorStyles
[System.Flags]
public enum AnchorStyles
[<System.Flags>]
type AnchorStyles =
Public Enum AnchorStyles
- Öröklődés
- Attribútumok
Mezők
| Name | Érték | Description |
|---|---|---|
| None | 0 | A vezérlő nincs rögzítve a tároló széleihez. |
| Top | 1 | A vezérlő a tároló felső széléhez van rögzítve. |
| Bottom | 2 | A vezérlő a tároló alsó széléhez van rögzítve. |
| Left | 4 | A vezérlő a tároló bal széléhez van rögzítve. |
| Right | 8 | A vezérlő a tároló jobb széléhez van rögzítve. |
Példák
Az alábbi példa hozzáad egy Button űrlapot, és beállítja annak néhány gyakori tulajdonságát. A példa az űrlap jobb alsó sarkához rögzíti a gombot, így megtartja a relatív pozícióját az űrlap átméretezésekor. Ezután beállítja a BackgroundImage gombot, és átméretezi a gombot a méretével Imagemegegyező méretre. A példa ezután beállítja a TabStop tulajdonságot true , és beállítja azt TabIndex . Végül hozzáad egy eseménykezelőt a Click gomb eseményének kezeléséhez. Ez a példa feltételezi, hogy van egy ImageList neve imageList1.
// 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
Megjegyzések
Ha egy vezérlő a tároló egy széléhez van rögzítve, a vezérlő és a megadott él közötti távolság állandó marad a tároló átméretezésekor. Ha például egy vezérlő a tároló jobb széléhez van rögzítve, a vezérlő jobb széle és a tároló jobb széle közötti távolság állandó marad a tároló átméretezésekor. A vezérlők a vezérlő élek tetszőleges kombinációjához rögzíthetők. Ha a vezérlő a tároló ellentétes széleihez van rögzítve (például felül és alul), akkor átméretezi a tároló átméretezésekor. Ha egy vezérlő tulajdonsága Anchor Nincs értékre van állítva, a vezérlő a vezérlő tárolójának átméretezésétől való távolság felét mozgatja. Ha például egy Button adott tulajdonsága Anchor Nincs értékre van állítva, és a Form vezérlőelem helye mindkét irányban 20 képponttal van átméretezve, a gomb mindkét irányban 10 képponttal lesz áthelyezve.