通过


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 组框,并将组框停靠在窗体顶部。 最后,它通过将属性false设置为Enabled禁用组框来禁用组框,这将导致禁用组框中包含的所有控件。

   // 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 属性和 set 方法 Dock ;仅可根据需要替代一个。

适用于

另请参阅