Freigeben über


AnchorStyles-Enumeration

Gibt die Art der Verankerung eines Steuerelements an den Rändern des zugehörigen Containers an.

Diese Enumeration verfügt über ein FlagsAttribute -Attribut, das die bitweise Kombination der Memberwerte zulässt.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
<FlagsAttribute> _
Public Enumeration AnchorStyles
'Usage
Dim instance As AnchorStyles
[FlagsAttribute] 
public enum AnchorStyles
[FlagsAttribute] 
public enum class AnchorStyles
/** @attribute FlagsAttribute() */ 
public enum AnchorStyles
FlagsAttribute 
public enum AnchorStyles

Member

  Membername Beschreibung
Unterstützt von .NET Compact Framework Bottom Das Steuerelement ist am unteren Rand des zugehörigen Containers verankert. 
Unterstützt von .NET Compact Framework Left Das Steuerelement ist am linken Rand des zugehörigen Containers verankert. 
Unterstützt von .NET Compact Framework None Das Steuerelement ist an keinem Rand des zugehörigen Containers verankert. 
Unterstützt von .NET Compact Framework Right Das Steuerelement ist am rechten Rand des zugehörigen Containers verankert. 
Unterstützt von .NET Compact Framework Top Das Steuerelement ist am oberen Rand des zugehörigen Containers verankert. 

Hinweise

Wenn ein Steuerelement am Rand des zugehörigen Containers verankert ist, bleibt der Abstand zwischen dem Steuerelement und dem angegebenen Rand bei einer Größenänderung der Containers konstant. Wenn ein Steuerelement z. B. am rechten Rand des zugehörigen Containers verankert ist, bleibt der Abstand zwischen dem rechten Rand des Steuerelements und dem rechten Rand des Containers bei einer Größenänderung des Containers konstant. Ein Steuerelement kann an einer beliebigen Kombination von Rändern verankert werden. Wenn das Steuerelement an gegenüberliegenden Rändern des Containers (z. B. oben und unten) verankert ist, ändert sich seine Größe mit der Größe des Cointainers. Wenn die Anchor-Eigenschaft eines Steuerelements auf AnchorStyles.None festgelegt ist, wird das Steuerelement um die Hälfte des Werts verschoben, um den die Größe des entsprechenden Containers geändert wird. Wenn z. B. die Anchor-Eigenschaft von Button auf AnchorStyles.None festgelegt ist und das Form, in dem das Steuerelement enthalten ist, um 20 Pixel in einer der Richtungen vergrößert wird, wird die Schaltfläche um 10 Pixel in beide Richtungen verschoben.

Beispiel

Im folgenden Codebeispiel werden eine Button zu einem Formular hinzugefügt und einige allgemeine Eigenschaften des Formulars festgelegt. Im Beispiel wird die Schaltfläche in der rechten unteren Ecke des Formulars verankert, sodass sie auch dann ihre relative Position beibehält, wenn die Größe des Formulars geändert wird. Anschließend wird BackgroundImage festgelegt und die Größe der Schaltfläche auf dieselbe Größe wie Image angepasst. Im Beispiel wird TabStop anschließend auf true festgelegt und die TabIndex-Eigenschaft festgelegt. Abschließend wird ein Ereignishandler hinzugefügt, um das Click-Ereignis der Schaltfläche zu behandeln. In diesem Beispiel wird davon ausgegangen, dass eine ImageList mit dem Namen imageList1 vorhanden ist.

' 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
// 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:
   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.set_Anchor(AnchorStyles.Bottom | AnchorStyles.Right);
    // Assign a background image.
    button1.set_BackgroundImage(imageList1.get_Images().get_Item(0));
    // Specify the layout style of the background image. Tile is the 
    // default.
    button1.set_BackgroundImageLayout(ImageLayout.Center);
    // Make the button the same size as the image.
    button1.set_Size(button1.get_BackgroundImage().get_Size());
    // Set the button's TabIndex and TabStop properties.
    button1.set_TabIndex(1);
    button1.set_TabStop(true);
    // Add a delegate to handle the Click event.
    button1.add_Click(new System.EventHandler(this.button1_Click));
    // Add the button to the form.
    this.get_Controls().Add(button1);
} //AddMyButton

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0

Siehe auch

Referenz

System.Windows.Forms-Namespace
Anchor