Control.Dock Control.Dock Control.Dock Control.Dock Property

定義

取得或設定停駐在其父控制項的控制項框線,並決定控制項隨其父代重新調整大小的方式。Gets or sets which control borders are docked to its parent control and determines how a control is resized with its parent.

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 值。One of the DockStyle values. 預設為 NoneThe default is None.

例外狀況

指派的值不是其中一個DockStyle值。The value assigned is not one of the DockStyle values.

範例

下列程式碼範例會建立GroupBox和設定的某些常見屬性。The following code example creates a GroupBox and sets some of its common properties. 此範例會建立TextBox,並設定其Location群組方塊內。The example creates a TextBox and sets its Location within the group box. 接下來,它會設定Text屬性群組 方塊中,並群組方塊的停駐在表單頂端。Next, it sets the Text property of the group box, and docks the group box to the top of the form. 最後,它會停用 [群組] 中設定Enabled屬性設false,因而導致停用群組內包含的所有控制項。Lastly, it disables the group box by setting the Enabled property to false, which causes all controls contained within the group box to be disabled.

   // 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屬性來定義控制項自動調整大小的方式其父控制項調整大小時。Use the Dock property to define how a control is automatically resized as its parent control is resized. 例如,設定DockDockStyle.Left會讓控制項對齊其父控制項的左邊緣與,並調整大小的父控制項調整大小時。For example, setting Dock to DockStyle.Left causes the control to align itself with the left edges of its parent control and to resize as the parent control is resized. 控制項停駐在其的疊置順序,也就是表單的 z 軸 (深度) 以及在表單上控制項的視覺分層。Controls are docked in their Z-order, which is the visual layering of controls on a form along the form's Z-axis (depth).

控制項可以固定到其父容器的一個邊緣或所有邊緣可以停都駐並填滿父容器。A control can be docked to one edge of its parent container or can be docked to all edges and fill the parent container.

設定Margin停駐的控制項上的屬性沒有任何影響的控制項與其容器邊緣的距離。Setting the Margin property on a docked control has no effect on the distance of the control from the edges of its container.

注意

AnchorDock屬性互斥。The Anchor and Dock properties are mutually exclusive. 只有一個可以設定一次和最後一個設定的優先順序。Only one can be set at a time, and the last one set takes precedence.

給繼承者的注意事項

當覆寫Dock屬性在衍生類別中,使用基底類別的Dock擴充的基底實作的屬性。When overriding the Dock property in a derived class, use the base class's Dock property to extend the base implementation. 否則,您必須提供所有的實作。Otherwise, you must provide all the implementation. 您不需要覆寫兩個getset方法Dock屬性; 您可以覆寫只能有一個如有需要。You are not required to override both the get and set methods of the Dock property; you can override only one if needed.

適用於

另請參閱