共用方式為


AnchorStyles 列舉

定義

指定控件如何錨定至其容器邊緣。

此列舉支援其成員值的位元組合。

public enum class AnchorStyles
[System.Flags]
public enum AnchorStyles
[<System.Flags>]
type AnchorStyles = 
Public Enum AnchorStyles
繼承
AnchorStyles
屬性

欄位

名稱 Description
None 0

控制裝置並未固定於容器的任何邊緣。

Top 1

控制裝置固定在容器的頂緣。

Bottom 2

控制裝置固定在容器的底部邊緣。

Left 4

控制裝置固定在容器的左側邊緣。

Right 8

控制裝置固定在容器的右側邊緣。

範例

以下範例將 a Button 加入形式,並設定其一些常見性質。 範例中將按鈕固定在表單的右下角,以保持表單調整大小時的相對位置。 接著它設定 , BackgroundImage 並將按鈕調整到和 Image. 相同的大小。 範例接著設定 到 TabStoptrue設定屬性。TabIndex 最後,它新增了一個事件處理程序來處理 Click 按鈕事件。 這個例子假設你有一個 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

備註

當控制項固定在容器的邊緣時,容器重新調整大小時,控制節點與指定邊緣之間的距離保持不變。 例如,如果一個控制項被錨定在容器的右邊,當容器重新調整大小時,控制項右邊與容器右邊之間的距離保持不變。 控制點可以錨定在任意組合的控制邊上。 如果控制器固定在容器的相對邊緣(例如上下),當容器大小調整時,控制器也會調整大小。 若控制項屬性設 Anchor 為無,控制項移動的距離約為控制容器調整長度的一半。 例如,若 a ButtonAnchor 屬性設為 None,且控制鍵所在的 在 Form 任一方向調整大小 20 像素,按鈕將雙向移動 10 像素。

適用於

另請參閱