AnchorStyles Enumerazione
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Specifica la modalità di ancoraggio di un controllo ai bordi del relativo contenitore.
Questa enumerazione supporta una combinazione bit per bit dei rispettivi valori dei membri.
public enum class AnchorStyles
[System.Flags]
public enum AnchorStyles
[<System.Flags>]
type AnchorStyles =
Public Enum AnchorStyles
- Ereditarietà
- Attributi
Campi
| Nome | Valore | Descrizione |
|---|---|---|
| None | 0 | Il controllo non è ancorato ad alcun bordo del relativo contenitore. |
| Top | 1 | Il controllo viene ancorato al bordo superiore del contenitore. |
| Bottom | 2 | Il controllo è ancorato al bordo inferiore del contenitore. |
| Left | 4 | Il controllo è ancorato al bordo sinistro del contenitore. |
| Right | 8 | Il controllo viene ancorato al bordo destro del contenitore. |
Esempio
Nell'esempio seguente viene aggiunto un oggetto Button a una maschera e vengono impostate alcune delle relative proprietà comuni. Nell'esempio il pulsante viene ancorato all'angolo inferiore destro del form in modo da mantenere la relativa posizione relativa man mano che viene ridimensionata la maschera. Imposta quindi e BackgroundImage ridimensiona il pulsante con le stesse dimensioni di Image. Nell'esempio viene quindi impostato su TabStoptrue e viene impostata la TabIndex proprietà . Infine, aggiunge un gestore eventi per gestire l'evento Click del pulsante. In questo esempio si presuppone che sia presente un ImageList oggetto denominato 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
Commenti
Quando un controllo viene ancorato a un bordo del contenitore, la distanza tra il controllo e il bordo specificato rimane costante quando il contenitore viene ridimensionato. Ad esempio, se un controllo viene ancorato al bordo destro del contenitore, la distanza tra il bordo destro del controllo e il bordo destro del contenitore rimane costante quando il contenitore viene ridimensionato. Un controllo può essere ancorato a qualsiasi combinazione di bordi di controllo. Se il controllo è ancorato ai bordi opposti del contenitore, ad esempio all'inizio e al basso, viene ridimensionato quando il contenitore viene ridimensionato. Se una proprietà di un controllo è Anchor impostata su Nessuno, il controllo sposta metà della distanza ridimensionata dal contenitore del controllo. Ad esempio, se un oggetto Button ha la proprietà Anchor impostata su Nessuno e l'oggetto Form su cui si trova il controllo viene ridimensionato di 20 pixel in entrambe le direzioni, il pulsante verrà spostato di 10 pixel in entrambe le direzioni.