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

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

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

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

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

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