Partager via


AnchorStyles Énumération

Définition

Spécifie comment un contrôle ancre aux bords de son conteneur.

Cette énumération prend en charge une combinaison au niveau du bit de ses valeurs membres.

public enum class AnchorStyles
[System.Flags]
public enum AnchorStyles
[<System.Flags>]
type AnchorStyles = 
Public Enum AnchorStyles
Héritage
AnchorStyles
Attributs

Champs

Nom Valeur Description
None 0

Le contrôle n’est ancré à aucun bord de son conteneur.

Top 1

Le contrôle est ancré au bord supérieur de son conteneur.

Bottom 2

Le contrôle est ancré au bord inférieur de son conteneur.

Left 4

Le contrôle est ancré sur le bord gauche de son conteneur.

Right 8

Le contrôle est ancré au bord droit de son conteneur.

Exemples

L’exemple suivant ajoute un Button formulaire et définit certaines de ses propriétés communes. L’exemple ancre le bouton dans le coin inférieur droit du formulaire afin qu’il conserve sa position relative lorsque le formulaire est redimensionné. Ensuite, il définit le BackgroundImage bouton et redimensionne le bouton sur la même taille que le Image. L’exemple définit ensuite la TabStoptrue valeur et définit la TabIndex propriété. Enfin, il ajoute un gestionnaire d’événements pour gérer l’événement Click du bouton. Cet exemple part du principe que vous avez un ImageList nom 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

Remarques

Lorsqu’un contrôle est ancré à un bord de son conteneur, la distance entre le contrôle et le bord spécifié reste constante lorsque le conteneur est redimensionné. Par exemple, si un contrôle est ancré au bord droit de son conteneur, la distance entre le bord droit du contrôle et le bord droit du conteneur reste constante lorsque le conteneur est redimensionné. Un contrôle peut être ancré à n’importe quelle combinaison de bords de contrôle. Si le contrôle est ancré à des bords opposés de son conteneur (par exemple, en haut et en bas), il se redimensionne lorsque le conteneur est redimensionné. Si une propriété a la Anchor valeur None pour un contrôle, le contrôle déplace la moitié de la distance que le conteneur du contrôle est redimensionné. Par exemple, si une Button propriété a la Anchor valeur None et Form que le contrôle est redimensionné de 20 pixels dans les deux sens, le bouton est déplacé de 10 pixels dans les deux sens.

S’applique à

Voir aussi