DockStyle 枚举

定义

指定控件停靠的位置和方式。

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

字段

Bottom 2

该控件的下边缘停靠在其包含控件的底部。

Fill 5

控件的各个边缘分别停靠在其包含控件的各个边缘,并且适当调整大小。

Left 3

该控件的左边缘停靠在其包含控件的左边缘。

None 0

该控件未停靠。

Right 4

该控件的右边缘停靠在其包含控件的右边缘。

Top 1

该控件的上边缘停靠在其包含控件的顶端。

示例

以下示例创建 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

注解

当控件停靠在其容器的边缘时,在调整容器大小时,它始终会针对该边缘进行刷新。 如果多个控件停靠在边缘,控件会按 z 顺序并排显示:z 顺序中的控件在远离容器边缘的位置更远。

如果选择了“左”、“右”、“上”或“下”,则控件的指定和相反边缘的大小将调整为包含控件的相应边缘的大小。 如果选择了 Fill,则调整控件的所有四侧的大小以匹配包含控件的边缘。

适用于

另请参阅