Splitter 构造函数

定义

初始化 Splitter 类的新实例。 Splitter 已被 SplitContainer 取代,提供它仅是为了兼容早期版本。

public:
 Splitter();
public Splitter ();
Public Sub New ()

示例

下面的代码示例结合使用控件TreeViewListView控件创建类似于SplitterWindows资源管理器的窗口。 若要标识 TreeViewListView 控件,会将节点和项添加到这两个控件。 该示例使用和MinExtraMinSize属性Splitter来防止TreeViewListView控件的大小过小或太大。 此示例要求在本示例中创建的方法在一个 Form 内部定义,并且从构造 Form函数调用该方法。

private:
   void CreateMySplitControls()
   {
      // Create TreeView, ListView, and Splitter controls.
      TreeView^ treeView1 = gcnew TreeView;
      ListView^ listView1 = gcnew ListView;
      Splitter^ splitter1 = gcnew Splitter;

      // Set the TreeView control to dock to the left side of the form.
      treeView1->Dock = DockStyle::Left;

      // Set the Splitter to dock to the left side of the TreeView control.
      splitter1->Dock = DockStyle::Left;

      // Set the minimum size the ListView control can be sized to.
      splitter1->MinExtra = 100;

      // Set the minimum size the TreeView control can be sized to.
      splitter1->MinSize = 75;

      // Set the ListView control to fill the remaining space on the form.
      listView1->Dock = DockStyle::Fill;

      // Add a TreeView and a ListView item to identify the controls on the form.
      treeView1->Nodes->Add( "TreeView Node" );
      listView1->Items->Add( "ListView Item" );

      // Add the controls in reverse order to the form to ensure proper location.
      array<Control^>^temp0 = {listView1,splitter1,treeView1};
      this->Controls->AddRange( temp0 );
   }
private void CreateMySplitControls()
{
    // Create TreeView, ListView, and Splitter controls.
    TreeView treeView1 = new TreeView();
    ListView listView1 = new ListView();
    Splitter splitter1 = new Splitter();

    // Set the TreeView control to dock to the left side of the form.
    treeView1.Dock = DockStyle.Left;
    // Set the Splitter to dock to the left side of the TreeView control.
    splitter1.Dock = DockStyle.Left;
    // Set the minimum size the ListView control can be sized to.
    splitter1.MinExtra = 100;
    // Set the minimum size the TreeView control can be sized to.
    splitter1.MinSize = 75;
    // Set the ListView control to fill the remaining space on the form.
    listView1.Dock = DockStyle.Fill;
    // Add a TreeView and a ListView item to identify the controls on the form.
    treeView1.Nodes.Add("TreeView Node");
    listView1.Items.Add("ListView Item");

    // Add the controls in reverse order to the form to ensure proper location.
    this.Controls.AddRange(new Control[]{listView1, splitter1, treeView1});
}
Private Sub CreateMySplitControls()
   ' Create TreeView, ListView, and Splitter controls.
   Dim treeView1 As New TreeView()
   Dim listView1 As New ListView()
   Dim splitter1 As New Splitter()
   
   ' Set the TreeView control to dock to the left side of the form.
   treeView1.Dock = DockStyle.Left
   ' Set the Splitter to dock to the left side of the TreeView control.
   splitter1.Dock = DockStyle.Left
   ' Set the minimum size the ListView control can be sized to.
      splitter1.MinExtra = 100
   ' Set the minimum size the TreeView control can be sized to.
      splitter1.MinSize = 75
   ' Set the ListView control to fill the remaining space on the form.
      listView1.Dock = DockStyle.Fill

      ' Add a TreeView and a ListView item to identify the controls on the form.
      treeView1.Nodes.Add("TreeView Node")
      listView1.Items.Add("ListView Item")
   
   ' Add the controls in reverse order to the form to ensure proper location.
   Me.Controls.AddRange(New Control() {listView1, splitter1, treeView1})
End Sub

注解

默认情况下, MinSize 属性 MinExtra 设置为 25。 The Dock property is set to DockStyle.Left by default.

适用于