Control.Dock 屬性

定義

取得或設定停駐在其父控制項的控制項框線,並決定控制項隨其父代重新調整大小的方式。

public:
 virtual property System::Windows::Forms::DockStyle Dock { System::Windows::Forms::DockStyle get(); void set(System::Windows::Forms::DockStyle value); };
public virtual System.Windows.Forms.DockStyle Dock { get; set; }
member this.Dock : System.Windows.Forms.DockStyle with get, set
Public Overridable Property Dock As DockStyle

屬性值

其中一個 DockStyle 值。 預設值為 None

例外狀況

所指派的值不是其中一個 DockStyle 值。

範例

下列程式碼範例會建立 , GroupBox 並設定其一些通用屬性。 此範例會建立 , TextBox 並在群組方塊中設定其 Location 。 接下來,它會設定 Text 群組方塊的 屬性,並將群組方塊停駐在表單頂端。 最後,它會將 屬性設定 Enabledfalse 來停用群組方塊,這會導致停用群組方塊中包含的所有控制項。

   // Add a GroupBox to a form and set some of its common properties.
private:
   void AddMyGroupBox()
   {
      // Create a GroupBox and add a TextBox to it.
      GroupBox^ groupBox1 = gcnew GroupBox;
      TextBox^ textBox1 = gcnew TextBox;
      textBox1->Location = Point(15,15);
      groupBox1->Controls->Add( textBox1 );

      // Set the Text and Dock properties of the GroupBox.
      groupBox1->Text = "MyGroupBox";
      groupBox1->Dock = DockStyle::Top;

      // Disable the GroupBox (which disables all its child controls)
      groupBox1->Enabled = false;

      // Add the Groupbox to the form.
      this->Controls->Add( groupBox1 );
   }
// Add a GroupBox to a form and set some of its common properties.
private void AddMyGroupBox()
{
   // Create a GroupBox and add a TextBox to it.
   GroupBox groupBox1 = new GroupBox();
   TextBox textBox1 = new TextBox();
   textBox1.Location = new Point(15, 15);
   groupBox1.Controls.Add(textBox1);

   // Set the Text and Dock properties of the GroupBox.
   groupBox1.Text = "MyGroupBox";
   groupBox1.Dock = DockStyle.Top;

   // Disable the GroupBox (which disables all its child controls)
   groupBox1.Enabled = false;

   // Add the Groupbox to the form.
   this.Controls.Add(groupBox1);
}
' Add a GroupBox to a form and set some of its common properties.
Private Sub AddMyGroupBox()
   ' Create a GroupBox and add a TextBox to it.
   Dim groupBox1 As New GroupBox()
   Dim textBox1 As New TextBox()
   textBox1.Location = New Point(15, 15)
   groupBox1.Controls.Add(textBox1)
   
   ' Set the Text and Dock properties of the GroupBox.
   groupBox1.Text = "MyGroupBox"
   groupBox1.Dock = DockStyle.Top
   
   ' Disable the GroupBox (which disables all its child controls)
   groupBox1.Enabled = False
   
   ' Add the Groupbox to the form.
   Me.Controls.Add(groupBox1)
End Sub

備註

Dock使用 屬性來定義當控制項的父控制項調整大小時,控制項自動調整大小的方式。 例如,設定 DockDockStyle.Left 會使控制項與父控制項的左邊緣對齊,並在父控制項調整大小時調整大小。 控制項會依 Z 順序停駐,這是表單上控制項的視覺分層,沿著表單的 Z 軸 (深度) 。

控制項可以停駐到其父容器的一個邊緣,也可以停駐到所有邊緣並填滿父容器。

Margin在停駐控制項上設定 屬性不會影響控制項與其容器邊緣的距離。

注意

AnchorDock 屬性互斥。 一次只能設定一個,最後一個集合優先。

給繼承者的注意事項

在衍生類別中覆 Dock 寫 屬性時,請使用基類的 Dock 屬性來擴充基底實作。 否則,您必須提供所有實作。 您不需要同時覆寫 get 屬性的 Dockset 方法;您可以視需要只覆寫一個。

適用於

另請參閱