当前位置: 首页>>代码示例>>C#>>正文


C# SplitContainer类代码示例

本文整理汇总了C#中System.Windows.Forms.SplitContainer的典型用法代码示例。如果您正苦于以下问题:C# SplitContainer类的具体用法?C# SplitContainer怎么用?C# SplitContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SplitContainer类属于System.Windows.Forms命名空间,在下文中一共展示了SplitContainer类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Form1

//引入命名空间
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

public class 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();
    }

    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.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]
    static void Main() 
    {
        Application.Run(new Form1());
    }

    private void 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;
    }

    private void 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;
    }
}
开发者ID:.NET开发者,项目名称:System.Windows.Forms,代码行数:146,代码来源:SplitContainer

示例2: new SplitContainer()

//引入命名空间
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form
{

  private System.Windows.Forms.SplitContainer splitContainer1;
  private System.Windows.Forms.SplitContainer splitContainer2;
  private System.Windows.Forms.WebBrowser webBrowser1;
  private System.Windows.Forms.TextBox TextBox1;
  private System.Windows.Forms.Panel pnlFileList;
  private System.Windows.Forms.Button cmdHide;
  private System.Windows.Forms.ListView ListView1;
  private System.Windows.Forms.ColumnHeader ColumnHeader1;
  private System.Windows.Forms.Panel pnlShow;
  private System.Windows.Forms.Button cmdShow;
  public Form1() {
        InitializeComponent();
        ListView1.Items.Add("A");
        ListView1.Items.Add("B");
        ListView1.Items.Add("C");
  }
  private void cmdHide_Click(object sender, EventArgs e)
  {
    splitContainer1.Panel1Collapsed = true;
    pnlShow.Visible = true;

  }

  private void cmdShow_Click(object sender, EventArgs e)
  {
    splitContainer1.Panel1Collapsed = false;
    pnlShow.Visible = false;
    

  }

  private void InitializeComponent()
  {
        this.splitContainer1 = new System.Windows.Forms.SplitContainer();
        this.pnlFileList = new System.Windows.Forms.Panel();
        this.cmdHide = new System.Windows.Forms.Button();
        this.ListView1 = new System.Windows.Forms.ListView();
        this.ColumnHeader1 = new System.Windows.Forms.ColumnHeader();
        this.splitContainer2 = new System.Windows.Forms.SplitContainer();
        this.webBrowser1 = new System.Windows.Forms.WebBrowser();
        this.TextBox1 = new System.Windows.Forms.TextBox();
        this.pnlShow = new System.Windows.Forms.Panel();
        this.cmdShow = new System.Windows.Forms.Button();
        this.splitContainer1.Panel1.SuspendLayout();
        this.splitContainer1.Panel2.SuspendLayout();
        this.splitContainer1.SuspendLayout();
        this.pnlFileList.SuspendLayout();
        this.splitContainer2.Panel1.SuspendLayout();
        this.splitContainer2.Panel2.SuspendLayout();
        this.splitContainer2.SuspendLayout();
        this.pnlShow.SuspendLayout();
        this.SuspendLayout();
        // 
        // splitContainer1
        // 
        this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
        this.splitContainer1.Location = new System.Drawing.Point(29, 10);
        this.splitContainer1.Name = "splitContainer1";
        // 
        // splitContainer1.Panel1
        // 
        this.splitContainer1.Panel1.Controls.Add(this.pnlFileList);
        this.splitContainer1.Panel1MinSize = 50;
        // 
        // splitContainer1.Panel2
        // 
        this.splitContainer1.Panel2.Controls.Add(this.splitContainer2);
        this.splitContainer1.Size = new System.Drawing.Size(477, 366);
        this.splitContainer1.SplitterDistance = 155;
        this.splitContainer1.TabIndex = 0;
        this.splitContainer1.Text = "splitContainer1";
        // 
        // pnlFileList
        // 
        this.pnlFileList.Controls.Add(this.cmdHide);
        this.pnlFileList.Controls.Add(this.ListView1);
        this.pnlFileList.Dock = System.Windows.Forms.DockStyle.Fill;
        this.pnlFileList.Location = new System.Drawing.Point(0, 0);
        this.pnlFileList.Name = "pnlFileList";
        this.pnlFileList.Padding = new System.Windows.Forms.Padding(0, 0, 1, 0);
        this.pnlFileList.Size = new System.Drawing.Size(155, 366);
        this.pnlFileList.TabIndex = 21;
        // 
        // cmdHide
        // 
        this.cmdHide.Dock = System.Windows.Forms.DockStyle.Bottom;
        this.cmdHide.FlatStyle = System.Windows.Forms.FlatStyle.System;
        this.cmdHide.Location = new System.Drawing.Point(0, 346);
        this.cmdHide.Name = "cmdHide";
        this.cmdHide.Size = new System.Drawing.Size(154, 20);
        this.cmdHide.TabIndex = 23;
        this.cmdHide.Text = "<< Hide";
        this.cmdHide.Click += new System.EventHandler(this.cmdHide_Click);
        // 
        // ListView1
        // 
        this.ListView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                    | System.Windows.Forms.AnchorStyles.Left)
                    | System.Windows.Forms.AnchorStyles.Right)));
        this.ListView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
        this.ColumnHeader1});
        this.ListView1.Location = new System.Drawing.Point(0, 3);
        this.ListView1.Name = "ListView1";
        this.ListView1.Size = new System.Drawing.Size(152, 337);
        this.ListView1.TabIndex = 22;
        this.ListView1.UseCompatibleStateImageBehavior = false;
        this.ListView1.View = System.Windows.Forms.View.Details;
        // 
        // ColumnHeader1
        // 
        this.ColumnHeader1.Name = "ColumnHeader1";
        this.ColumnHeader1.Text = "File";
        this.ColumnHeader1.Width = 99;
        // 
        // splitContainer2
        // 
        this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;
        this.splitContainer2.Location = new System.Drawing.Point(0, 0);
        this.splitContainer2.Name = "splitContainer2";
        this.splitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal;
        // 
        // splitContainer2.Panel1
        // 
        this.splitContainer2.Panel1.Controls.Add(this.webBrowser1);
        // 
        // splitContainer2.Panel2
        // 
        this.splitContainer2.Panel2.Controls.Add(this.TextBox1);
        this.splitContainer2.Size = new System.Drawing.Size(318, 366);
        this.splitContainer2.SplitterDistance = 173;
        this.splitContainer2.TabIndex = 0;
        this.splitContainer2.Text = "splitContainer2";
        // 
        // webBrowser1
        // 
        this.webBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
        this.webBrowser1.Location = new System.Drawing.Point(0, 0);
        this.webBrowser1.Name = "webBrowser1";
        this.webBrowser1.Size = new System.Drawing.Size(318, 173);
        this.webBrowser1.TabIndex = 0;
        // 
        // TextBox1
        // 
        this.TextBox1.Dock = System.Windows.Forms.DockStyle.Fill;
        this.TextBox1.Location = new System.Drawing.Point(0, 0);
        this.TextBox1.Multiline = true;
        this.TextBox1.Name = "TextBox1";
        this.TextBox1.ReadOnly = true;
        this.TextBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
        this.TextBox1.Size = new System.Drawing.Size(318, 189);
        this.TextBox1.TabIndex = 1;
        // 
        // pnlShow
        // 
        this.pnlShow.Controls.Add(this.cmdShow);
        this.pnlShow.Dock = System.Windows.Forms.DockStyle.Left;
        this.pnlShow.Location = new System.Drawing.Point(10, 10);
        this.pnlShow.Name = "pnlShow";
        this.pnlShow.Padding = new System.Windows.Forms.Padding(0, 0, 3, 0);
        this.pnlShow.Size = new System.Drawing.Size(19, 366);
        this.pnlShow.TabIndex = 23;
        this.pnlShow.Visible = false;
        // 
        // cmdShow
        // 
        this.cmdShow.Dock = System.Windows.Forms.DockStyle.Fill;
        this.cmdShow.FlatStyle = System.Windows.Forms.FlatStyle.System;
        this.cmdShow.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.cmdShow.Location = new System.Drawing.Point(0, 0);
        this.cmdShow.Name = "cmdShow";
        this.cmdShow.Size = new System.Drawing.Size(16, 366);
        this.cmdShow.TabIndex = 21;
        this.cmdShow.Text = ">";
        this.cmdShow.Click += new System.EventHandler(this.cmdShow_Click);
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(516, 386);
        this.Controls.Add(this.splitContainer1);
        this.Controls.Add(this.pnlShow);
        this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.Name = "Form1";
        this.Padding = new System.Windows.Forms.Padding(10);
        this.Text = "Split Window";
        this.splitContainer1.Panel1.ResumeLayout(false);
        this.splitContainer1.Panel2.ResumeLayout(false);
        this.splitContainer1.ResumeLayout(false);
        this.pnlFileList.ResumeLayout(false);
        this.splitContainer2.Panel1.ResumeLayout(false);
        this.splitContainer2.Panel2.ResumeLayout(false);
        this.splitContainer2.Panel2.PerformLayout();
        this.splitContainer2.ResumeLayout(false);
        this.pnlShow.ResumeLayout(false);
        this.ResumeLayout(false);

  }

  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
  }

}
开发者ID:C#程序员,项目名称:System.Windows.Forms,代码行数:219,代码来源:SplitContainer


注:本文中的System.Windows.Forms.SplitContainer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。