DockStyle DockStyle DockStyle DockStyle Enum

定义

指定控件停靠的位置和方式。Specifies the position and manner in which a control is docked.

public enum class DockStyle
public enum DockStyle
type DockStyle = 
Public Enum DockStyle
继承

字段

Bottom Bottom Bottom Bottom 2

该控件的下边缘停靠在其包含控件的底部。The control's bottom edge is docked to the bottom of its containing control.

Fill Fill Fill Fill 5

控件的各个边缘分别停靠在其包含控件的各个边缘,并且适当调整大小。All the control's edges are docked to the all edges of its containing control and sized appropriately.

Left Left Left Left 3

该控件的左边缘停靠在其包含控件的左边缘。The control's left edge is docked to the left edge of its containing control.

None None None None 0

该控件未停靠。The control is not docked.

Right Right Right Right 4

该控件的右边缘停靠在其包含控件的右边缘。The control's right edge is docked to the right edge of its containing control.

Top Top Top Top 1

该控件的上边缘停靠在其包含控件的顶端。The control's top edge is docked to the top of its containing control.

示例

下面的示例创建一个GroupBox并设置它的一些公共属性。The following 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

注解

当控件停靠到其容器的边缘时, 当调整容器大小时, 控件总是相对于该边缘进行定位。When a control is docked to an edge of its container, it is always positioned flush against that edge when the container is resized. 如果有多个控件停靠到边缘, 控件将根据其 z 顺序并排显示;z 顺序中较高的控件定位在离容器边缘更远的位置。If more than one control is docked to an edge, the controls appear side by side according to their z-order; controls higher in the z-order are positioned farther from the container's edge.

如果选择 "左"、"右"、"顶部" 或 "底部", 则会将控件的指定边缘和相反边缘调整为包含控件的相应边缘的大小。If Left, Right, Top, or Bottom is selected, the specified and opposite edges of the control are resized to the size of the containing control's corresponding edges. 如果选择了 "填充", 则控件的所有四个边都将调整大小以匹配包含控件的边缘。If Fill is selected, all four sides of the control are resized to match the containing control's edges.

适用于

另请参阅