SplitContainer.Dock 属性

定义

获取或设置附加到容器边缘的 SplitContainer 边框。

C#
public System.Windows.Forms.DockStyle Dock { get; set; }

属性值

DockStyle 值之一。 默认值是 None

示例

下面的代码示例演示了一个垂直拆分器,其 Dock 属性设置为 Fill。 还会显示垂直拆分器的其他基本属性。 此示例是为 类提供的更大示例的一 SplitContainer 部分。

C#
// Basic SplitContainer properties.
// This is a vertical splitter that moves in 10-pixel increments.
// This splitter needs no explicit Orientation property because Vertical is the default.
splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
splitContainer1.ForeColor = System.Drawing.SystemColors.Control;
splitContainer1.Location = new System.Drawing.Point(0, 0);
splitContainer1.Name = "splitContainer1";
// You can drag the splitter no nearer than 30 pixels from the left edge of the container.
splitContainer1.Panel1MinSize = 30;
// You can drag the splitter no nearer than 20 pixels from the right edge of the container.
splitContainer1.Panel2MinSize = 20;
splitContainer1.Size = new System.Drawing.Size(292, 273);
splitContainer1.SplitterDistance = 79;
// This splitter moves in 10-pixel increments.
splitContainer1.SplitterIncrement = 10;
splitContainer1.SplitterWidth = 6;
// splitContainer1 is the first control in the tab order.
splitContainer1.TabIndex = 0;
splitContainer1.Text = "splitContainer1";
// When the splitter moves, the cursor changes shape.
splitContainer1.SplitterMoved += new System.Windows.Forms.SplitterEventHandler(splitContainer1_SplitterMoved);
splitContainer1.SplitterMoving += new System.Windows.Forms.SplitterCancelEventHandler(splitContainer1_SplitterMoving);

// Add a TreeView control to the left panel.
splitContainer1.Panel1.BackColor = System.Drawing.SystemColors.Control;
// Add a TreeView control to Panel1.
splitContainer1.Panel1.Controls.Add(treeView1);
splitContainer1.Panel1.Name = "splitterPanel1";
// Controls placed on Panel1 support right-to-left fonts.
splitContainer1.Panel1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;

注解

可以将 停靠 SplitContainer 到其容器的任何边缘,也可以将 停靠 SplitContainer 到容器的所有边缘, SplitContainer 以便 完全填充容器。 例如,将此属性设置为 DockStyle.Left 以将 的 SplitContainer 左边缘附加到其容器的左边缘。 控件按 z 顺序停靠。

备注

z 顺序对应于屏幕的深度维度,x 顺序和 y 顺序分别对应于水平和垂直尺寸。 Z 顺序定义在控件或窗口可以重叠或占据屏幕上相同的空间的情况下,哪个对象出现在其前面。 z 顺序顶部的控件或窗口显示在所有其他控件或窗口的顶部,并由 属性中的 Controls 索引 0 引用。 z 顺序底部的控件或窗口显示在所有其他控件或窗口下方,并由 属性中的 Controls 索引(Controls.Count-1)引用。

有关定位和停靠控件的详细信息,请参阅如何:使用Windows 窗体创建多窗格用户界面

适用于

产品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另请参阅