Splitter 类

表示使用户可以调整停靠控件大小的拆分器控件。Splitter 已被 SplitContainer 取代,仅为与早期版本兼容而提供。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class Splitter
    Inherits Control
用法
Dim instance As Splitter
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
public class Splitter : Control
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
public ref class Splitter : public Control
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public class Splitter extends Control
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
public class Splitter extends Control

备注

Splitter 控件使用户可以在运行时调整停靠到 Splitter 控件边缘的控件的大小。当用户将鼠标指针移到 Splitter 控件上时,光标将更改以指示可以调整停靠到 Splitter 控件的那些控件的大小。Splitter 控件使用户可以调整在停靠顺序中紧靠它前面的停靠控件的大小。因此,若要使用户可以调整停靠控件的大小,则将希望用户能够调整大小的控件停靠到一个容器的边缘,然后将拆分器停靠到该容器的同一侧。例如,若要创建一个与 Windows 资源管理器类似的窗口,则将 TreeView 控件添加到一个窗体中,并将其 Dock 属性设置为 DockStyle.Left。同时,将 Splitter 控件添加到此窗体并将其 Dock 属性设置为 DockStyle.Left。若要完成窗体布局,则添加 ListView 控件并将其 Dock 属性设置为 DockStyle.Fill 从而使 ListView 占据窗体上的剩余空间。这样,在运行时,用户通过移动 Splitter 控件就可以重新调整 TreeView 控件(及 ListView 控件)的宽度。

若要确保 Splitter 控件不会将停靠的控件尺寸调整得太小而使用户无法使用,则使用 MinExtraMinSize 属性。MinExtraMinSize 属性确定停靠到左侧和右侧(如果是水平 Splitter 控件,则停靠到顶部和底部)的控件可调整到的最小尺寸。如果 Splitter 控件停靠到的窗体上的其他控件显示特定的边框样式,则可以使用 BorderStyle 属性来匹配停靠到该窗体上的控件的边框样式。

您可能希望对 Splitter 控件所停靠的控件设置最大尺寸限制。SplitterMovedSplitterMoving 事件使您可以确定用户何时调整停靠控件的大小。可以使用 SplitterMovedSplitterMoving 事件的事件处理程序中的 SplitPosition 属性来确定 Splitter 控件停靠到的控件的大小,并将 SplitPosition 属性设置为不同的值来将停靠控件的宽度限制到指定的最大宽度(或如果是水平对齐的 Splitter 控件,则指高度)。

提示

使用 Splitter 控件来调整控件的大小只能通过鼠标进行。使用键盘访问 Splitter 控件是不可能的。

示例

下面的代码示例将 Splitter 控件与 TreeViewListView 控件一起使用,来创建与 Windows 资源管理器类似的窗口。若要标识 TreeViewListView 控件,向这两个控件添加节点和项。该示例使用 SplitterMinExtraMinSize 属性,以防止将 TreeViewListView 控件调整得太小或太大。此示例要求在 Form 中定义在此示例中创建的方法,并要求从 Form 的构造函数中调用该方法。

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 'CreateMySplitControls
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:
   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.set_Dock(DockStyle.Left);
    // Set the Splitter to dock to the left side of the TreeView control.
    splitter1.set_Dock(DockStyle.Left);
    // Set the minimum size the ListView control can be sized to.
    splitter1.set_MinExtra(100);
    // Set the minimum size the TreeView control can be sized to.
    splitter1.set_MinSize(75);
    // Set the ListView control to fill the remaining space on the form.
    listView1.set_Dock(DockStyle.Fill);
    // Add a TreeView and a ListView item to identify the controls on the 
    // form.
    treeView1.get_Nodes().Add("TreeView Node");
    listView1.get_Items().Add("ListView Item");
    // Add the controls in reverse order to the form to ensure proper 
    // location.
    this.get_Controls().AddRange(new Control[] { listView1, splitter1, 
        treeView1 });
} //CreateMySplitControls

继承层次结构

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
        System.Windows.Forms.Splitter

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0

请参见

参考

Splitter 成员
System.Windows.Forms 命名空间
TreeView
ListView 类