AnchorStyles Enumeração

Definição

Especifica como um controlo se fixa nas bordas do seu contentor.

Esta enumeração suporta uma combinação bit-a-bit dos respetivos valores membro.

public enum class AnchorStyles
[System.Flags]
public enum AnchorStyles
[<System.Flags>]
type AnchorStyles = 
Public Enum AnchorStyles
Herança
AnchorStyles
Atributos

Campos

Name Valor Description
None 0

O controlo não está ancorado a nenhuma aresta do seu recipiente.

Top 1

O controlo está ancorado na borda superior do seu recipiente.

Bottom 2

O controlo está ancorado na borda inferior do seu recipiente.

Left 4

O controlo está ancorado na borda esquerda do seu recipiente.

Right 8

O controlo está ancorado na borda direita do seu contentor.

Exemplos

O exemplo seguinte adiciona a Button a a a uma forma e define algumas das suas propriedades comuns. O exemplo ancora o botão no canto inferior direito do formulário para que mantenha a sua posição relativa à medida que o formulário é redimensionado. De seguida, define o BackgroundImage e redimensiona o botão para o mesmo tamanho que o Image. O exemplo então define o TabStop para true e define a TabIndex propriedade. Por fim, adiciona um gestor de eventos para gerir o Click evento do botão. Este exemplo assume que tens um ImageList .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

Observações

Quando um controlo está ancorado numa aresta do seu contentor, a distância entre o controlo e a aresta especificada mantém-se constante quando o contentor muda de tamanho. Por exemplo, se um controlo estiver ancorado na extremidade direita do seu contentor, a distância entre a borda direita do controlo e a borda direita do contentor mantém-se constante quando o contentor muda de tamanho. Um controlo pode ser ancorado a qualquer combinação de arestas de controlo. Se o controlo estiver ancorado a bordas opostas do seu recipiente (por exemplo, no topo e na base), ele redimensiona quando o recipiente muda de tamanho. Se um controlo tiver Anchor a sua propriedade definida para Nenhuma, o controlo move-se metade da distância que o contentor do controlo é redimensionado. Por exemplo, se a Button tiver a sua Anchor propriedade definida para Nenhum e o Form onde o controlo está for redimensionado em 20 pixels em qualquer direção, o botão será movido 10 pixels em ambas as direções.

Aplica-se a

Ver também