Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
Tradução
Original
Este tópico ainda não foi avaliado como - Avalie este tópico

Classe SplitContainer

Representa um controle consiste em uma BAR móvel divide a área de exibição do contêiner em dois painéis redimensionáveis.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (em System.Windows.Forms.dll)
[DockingAttribute(DockingBehavior.AutoDock)]
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
public class SplitContainer : ContainerControl

Você pode adicionar controles para os dois painéis redimensionáveis e você pode adicionar outros SplitContainer controles existentes SplitContainer painéis para criar várias áreas de exibição redimensionável.

Use o SplitContainer controle para dividir a área de exibição de um contêiner (sistema autônomo um Form) e permite ao usuário redimensionar controles são adicionados ao SplitContainer painéis. Quando o usuário passa o ponteiro do mouse sobre o divisor, o cursor é alterado para indicar que os controles dentro de SplitContainer controle pode ser redimensionada.

Observação Observação:

Versões anteriores dos .NET Framework oferece suporte somente a Splitter controle.

SplitContainer também facilita o posicionamento do controle em time de design. Por exemplo, para criar uma janela semelhante ao Windows Explorer, adicione um SplitContainer o controle para um Form e conjunto seu Dock propriedade para DockStyle.Fill. Adicionar um TreeView o controle para o Form e defina seu Dock propriedade para DockStyle.Fill. Para concluir o layout, adicionar um ListView controlar e conjunto seus Dock propriedade para DockStyle.Fill para que o ListView ocupar o espaço restante no Form. Em time de execução, o usuário pode, em seguida, redimensionar a largura de ambos os controles usando o divisor. Use o FixedPanel propriedade para especificar um controle não deve ser redimensionado junto com o Form ou Outros contêiner.

Use SplitterDistance Para especificar onde o divisor começa em seu formulário. Use SplitterIncrement Para especificar quantos pixels divisor move cada vez. O padrão de SplitterIncrement é um pixel.

Use Panel1MinSize e Panel2MinSize Para especificar a distância a BAR divisora pode ser movida para a borda externa de um SplitContainer painel. O dimensionar mínimo do padrão de um painel é 25 pixels.

Use o Orientation propriedade para especificar orientação horizontal. A orientação padrão do SplitContainer é vertical.

Use o BorderStyle propriedade para especificar o estilo da borda das SplitContainer e coordenar seu estilo de borda com o estilo da borda dos controles que você adicionar à SplitContainer.

O exemplo de código a seguir mostra tanto um vertical e horizontalSplitContainer. O divisor vertical move em incrementos de 10 pixels. Painel esquerdo do vertical SplitContainer contém um TreeView controle e o painel direito contém um horizontal SplitContainer. Ambos sistema autônomo painéis do horizontal SplitContainer são preenchidos com ListView controles e o painel superior é definido sistema autônomo um FixedPanel para que ele não redimensionar quando você redimensiona o contêiner. Mover o divisor vertical eleva o SplitterMoving evento, representado nesse exemplo por uma alterar no estilo do cursor. The SplitterMoved evento é gerado quando você parar de mover o divisor. Isso é representado nesse exemplo pelo estilo do cursor revertendo para o padrão.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

publicclass Form1 : System.Windows.Forms.Form
{
    private System.Windows.Forms.SplitContainer splitContainer1;
    private System.Windows.Forms.TreeView treeView1;
    private System.Windows.Forms.SplitContainer splitContainer2;
    private System.Windows.Forms.ListView listView2;
    private System.Windows.Forms.ListView listView1;

	public Form1()
	{
	InitializeComponent();
	}
	privatevoid InitializeComponent()
	{
        splitContainer1 = new System.Windows.Forms.SplitContainer();
        treeView1 = new System.Windows.Forms.TreeView();
        splitContainer2 = new System.Windows.Forms.SplitContainer();
        listView1 = new System.Windows.Forms.ListView();
        listView2 = new System.Windows.Forms.ListView();
        splitContainer1.SuspendLayout();
        splitContainer2.SuspendLayout();
        SuspendLayout();

        // 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;


        // Add a SplitContainer to the right panel.
        splitContainer1.Panel2.Controls.Add(splitContainer2);
        splitContainer1.Panel2.Name = "splitterPanel2";

        // This TreeView control is in Panel1 of splitContainer1.
        treeView1.Dock = System.Windows.Forms.DockStyle.Fill;
        treeView1.ForeColor = System.Drawing.SystemColors.InfoText;
        treeView1.ImageIndex = -1;
        treeView1.Location = new System.Drawing.Point(0, 0);
        treeView1.Name = "treeView1";
        treeView1.SelectedImageIndex = -1;
        treeView1.Size = new System.Drawing.Size(79, 273);
        // treeView1 is the second control in the tab order.
        treeView1.TabIndex = 1;

        // Basic SplitContainer properties.// This is a horizontal splitter whose top and bottom panels are ListView controls. The top panel is fixed.
        splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;
        // The top panel remains the same size when the form is resized.
        splitContainer2.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
        splitContainer2.Location = new System.Drawing.Point(0, 0);
        splitContainer2.Name = "splitContainer2";
        // Create the horizontal splitter.
        splitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal;
        splitContainer2.Size = new System.Drawing.Size(207, 273);
        splitContainer2.SplitterDistance = 125;
        splitContainer2.SplitterWidth = 6;
        // splitContainer2 is the third control in the tab order.
        splitContainer2.TabIndex = 2;
        splitContainer2.Text = "splitContainer2";

        // This splitter panel contains the top ListView control.
        splitContainer2.Panel1.Controls.Add(listView1);
        splitContainer2.Panel1.Name = "splitterPanel3";

        // This splitter panel contains the bottom ListView control.
        splitContainer2.Panel2.Controls.Add(listView2);
        splitContainer2.Panel2.Name = "splitterPanel4";

        // This ListView control is in the top panel of splitContainer2.
        listView1.Dock = System.Windows.Forms.DockStyle.Fill;
        listView1.Location = new System.Drawing.Point(0, 0);
        listView1.Name = "listView1";
        listView1.Size = new System.Drawing.Size(207, 125);
        // listView1 is the fourth control in the tab order.
        listView1.TabIndex = 3;

        // This ListView control is in the bottom panel of splitContainer2.
        listView2.Dock = System.Windows.Forms.DockStyle.Fill;
        listView2.Location = new System.Drawing.Point(0, 0);
        listView2.Name = "listView2";
        listView2.Size = new System.Drawing.Size(207, 142);
        // listView2 is the fifth control in the tab order.
        listView2.TabIndex = 4;

        // These are basic properties of the form.
        ClientSize = new System.Drawing.Size(292, 273);
        Controls.Add(splitContainer1);
        Name = "Form1";
        Text = "Form1";
        splitContainer1.ResumeLayout(false);
        splitContainer2.ResumeLayout(false);
        ResumeLayout(false);
    }

	[STAThread]
    staticvoid Main() 
	{
		Application.Run(new Form1());
	}
    privatevoid splitContainer1_SplitterMoving(System.Object sender, System.Windows.Forms.SplitterCancelEventArgs e)
    {
    // As the splitter moves, change the cursor type.
    Cursor.Current = System.Windows.Forms.Cursors.NoMoveVert;
    }
    privatevoid splitContainer1_SplitterMoved(System.Object sender, System.Windows.Forms.SplitterEventArgs e)
    {
    // When the splitter stops moving, change the cursor back to the default.
    Cursor.Current=System.Windows.Forms.Cursors.Default;
    }
}


import System.*;
import System.Drawing.*;
import System.Collections.*;
import System.ComponentModel.*;
import System.Windows.Forms.*;
import System.Data.*;

public class Form1 extends System.Windows.Forms.Form
{
    private System.Windows.Forms.SplitContainer splitContainer1;
    private System.Windows.Forms.TreeView treeView1;
    private System.Windows.Forms.SplitContainer splitContainer2;
    private System.Windows.Forms.ListView listView2;
    private System.Windows.Forms.ListView listView1;

    public Form1()
    {
        InitializeComponent();
    } //Form1

    private void InitializeComponent()
    {
        splitContainer1 = new System.Windows.Forms.SplitContainer();
        treeView1 = new System.Windows.Forms.TreeView();
        splitContainer2 = new System.Windows.Forms.SplitContainer();
        listView1 = new System.Windows.Forms.ListView();
        listView2 = new System.Windows.Forms.ListView();
        splitContainer1.SuspendLayout();
        splitContainer2.SuspendLayout();
        SuspendLayout();

        // 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.set_Dock(System.Windows.Forms.DockStyle.Fill);
        splitContainer1.set_ForeColor(System.Drawing.SystemColors.get_Control());
        splitContainer1.set_Location(new System.Drawing.Point(0, 0));
        splitContainer1.set_Name("splitContainer1");

        // You can drag the splitter no nearer than 30 pixels from the 
        // left edge of the container.
        splitContainer1.set_Panel1MinSize(30);

        // You can drag the splitter no nearer than 20 pixels from the 
        // right edge of the container.
        splitContainer1.set_Panel2MinSize(20);
        splitContainer1.set_Size(new System.Drawing.Size(292, 273));
        splitContainer1.set_SplitterDistance(79);

        // This splitter moves in 10-pixel increments.
        splitContainer1.set_SplitterIncrement(10);
        splitContainer1.set_SplitterWidth(6);

        // splitContainer1 is the first control in the tab order.
        splitContainer1.set_TabIndex(0);
        splitContainer1.set_Text("splitContainer1");

        // When the splitter moves, the cursor changes shape.
        splitContainer1.add_SplitterMoved(new System.Windows.Forms.
            SplitterEventHandler(splitContainer1_SplitterMoved));
        splitContainer1.add_SplitterMoving(new System.Windows.Forms.
            SplitterCancelEventHandler(splitContainer1_SplitterMoving));

        // Add a TreeView control to the left panel.
        splitContainer1.get_Panel1().set_BackColor(System.Drawing.SystemColors.
            get_Control());

        // Add a TreeView control to Panel1.
        splitContainer1.get_Panel1().get_Controls().Add(treeView1);
        splitContainer1.get_Panel1().set_Name("splitterPanel1");

        // Controls placed on Panel1 support right-to-left fonts.
        splitContainer1.get_Panel1().set_RightToLeft(System.Windows.Forms.
            RightToLeft.Yes);

        // Add a SplitContainer to the right panel.
        splitContainer1.get_Panel2().get_Controls().Add(splitContainer2);
        splitContainer1.get_Panel2().set_Name("splitterPanel2");

        // This TreeView control is in Panel1 of splitContainer1.
        treeView1.set_Dock(System.Windows.Forms.DockStyle.Fill);
        treeView1.set_ForeColor(System.Drawing.SystemColors.
            get_InfoText());
        treeView1.set_ImageIndex(-1);
        treeView1.set_Location(new System.Drawing.Point(0, 0));
        treeView1.set_Name("treeView1");
        treeView1.set_SelectedImageIndex(-1);
        treeView1.set_Size(new System.Drawing.Size(79, 273));

        // treeView1 is the second control in the tab order.
        treeView1.set_TabIndex(1);

        // Basic SplitContainer properties.
        // This is a horizontal splitter whose top and bottom panels are 
        // ListView controls. The top panel is fixed.
        splitContainer2.set_Dock(System.Windows.Forms.DockStyle.Fill);

        // The top panel remains the same size when the form is resized.
        splitContainer2.set_FixedPanel(System.Windows.Forms.
            FixedPanel.Panel1);
        splitContainer2.set_Location(new System.Drawing.Point(0, 0));
        splitContainer2.set_Name("splitContainer2");

        // Create the horizontal splitter.
        splitContainer2.set_Orientation(System.Windows.Forms.
            Orientation.Horizontal);
        splitContainer2.set_Size(new System.Drawing.Size(207, 273));
        splitContainer2.set_SplitterDistance(125);
        splitContainer2.set_SplitterWidth(6);

        // splitContainer2 is the third control in the tab order.
        splitContainer2.set_TabIndex(2);
        splitContainer2.set_Text("splitContainer2");

        // This splitter panel contains the top ListView control.
        splitContainer2.get_Panel1().get_Controls().Add(listView1);
        splitContainer2.get_Panel1().set_Name("splitterPanel3");

        // This splitter panel contains the bottom ListView control.
        splitContainer2.get_Panel2().get_Controls().Add(listView2);
        splitContainer2.get_Panel2().set_Name("splitterPanel4");

        // This ListView control is in the top panel of splitContainer2.
        listView1.set_Dock(System.Windows.Forms.DockStyle.Fill);
        listView1.set_Location(new System.Drawing.Point(0, 0));
        listView1.set_Name("listView1");
        listView1.set_Size(new System.Drawing.Size(207, 125));

        // listView1 is the fourth control in the tab order.
        listView1.set_TabIndex(3);

        // This ListView control is in the bottom panel of splitContainer2.
        listView2.set_Dock(System.Windows.Forms.DockStyle.Fill);
        listView2.set_Location(new System.Drawing.Point(0, 0));
        listView2.set_Name("listView2");
        listView2.set_Size(new System.Drawing.Size(207, 142));

        // listView2 is the fifth control in the tab order.
        listView2.set_TabIndex(4);

        // These are basic properties of the form.
        set_ClientSize(new System.Drawing.Size(292, 273));
        get_Controls().Add(splitContainer1);
        set_Name("Form1");
        set_Text("Form1");
        splitContainer1.ResumeLayout(false);
        splitContainer2.ResumeLayout(false);
        ResumeLayout(false);
    } //InitializeComponent

    /** @attribute STAThread()
     */
    public static void main(String[] args)
    {
        Application.Run(new Form1());
    } //main

    private void splitContainer1_SplitterMoving(Object sender, 
        System.Windows.Forms.SplitterCancelEventArgs e)
    {
        // As the splitter moves, change the cursor type.
        get_Cursor().set_Current(System.Windows.Forms.Cursors.
            get_NoMoveVert());
    } //splitContainer1_SplitterMoving

    private void splitContainer1_SplitterMoved(Object sender, 
        System.Windows.Forms.SplitterEventArgs e)
    {
        // When the splitter stops moving, change the cursor 
        // back to the default.
        get_Cursor().set_Current(System.Windows.Forms.Cursors.
            get_Default());
    } //splitContainer1_SplitterMoved
} //Form1


Quaisquer membros static (Shared no Visual Basic) públicos deste tipo são thread-safe. Não há garantia de que qualquer membro de instância seja thread-safe.

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

o.NET Framework e.NET Compact Framework não oferecem suporte a todas as versões de cada plataforma. Para obter uma lista de versões suportadas, consulte Requisitos de sistema do .NET framework.

.NET Framework

Compatível com: 3.5, 3.0, 2.0
Isso foi útil para você?
(1500 caracteres restantes)
Conteúdo da Comunidade Adicionar
A Microsoft está realizando uma pesquisa online para saber sua opinião sobre o site do MSDN. Se você optar por participar, a pesquisa online lhe será apresentada quando você sair do site do MSDN.

Deseja participar?