How to use SPLITTER ?

2

2G

Put the tree on your form dock it Right, then put a splitter dock Right and
then the list dock Fill
Run it and move your mouse over the splitter , you will see what it does ;)
 
S

Stu Smith

First you'll need your container for both controls. This could be your form,
but it's often more likely to be a panel within the form.

Next place the list into the container, and dock it left.
Following that comes the splitter, also docked left. Note you may need to
change the width, and setting the border styles is helpful to see it when
designing.
Finally add the tree to the container, and dock it "fill".

Hope that helps.
Stu
 
M

Mark Broadbent

using the splitter for the first time can be a pain (as I found out).
Essentially for it to work right you need to have each of the respective
controls z-order correct (this can be changed in designer easily by using
the sendtoback on the control)

First control you need to dock left, splitter is docked left (so that it
should be touching the previous control), the next control dock is then set
to fill. Heres one I quickly knocked up for you.

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

namespace WindowsApplication5

{

/// <summary>

/// Summary description for Form1.

/// </summary>

public class Form1 : System.Windows.Forms.Form

{

private System.Windows.Forms.ListBox listBox1;

private System.Windows.Forms.Splitter splitter1;

private System.Windows.Forms.TreeView treeView1;

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

public Form1()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.listBox1 = new System.Windows.Forms.ListBox();

this.splitter1 = new System.Windows.Forms.Splitter();

this.treeView1 = new System.Windows.Forms.TreeView();

this.SuspendLayout();

//

// listBox1

//

this.listBox1.Dock = System.Windows.Forms.DockStyle.Left;

this.listBox1.Location = new System.Drawing.Point(0, 0);

this.listBox1.Name = "listBox1";

this.listBox1.Size = new System.Drawing.Size(120, 264);

this.listBox1.TabIndex = 0;

//

// splitter1

//

this.splitter1.Location = new System.Drawing.Point(120, 0);

this.splitter1.Name = "splitter1";

this.splitter1.Size = new System.Drawing.Size(3, 266);

this.splitter1.TabIndex = 1;

this.splitter1.TabStop = false;

//

// treeView1

//

this.treeView1.Dock = System.Windows.Forms.DockStyle.Fill;

this.treeView1.ImageIndex = -1;

this.treeView1.Location = new System.Drawing.Point(120, 0);

this.treeView1.Name = "treeView1";

this.treeView1.SelectedImageIndex = -1;

this.treeView1.Size = new System.Drawing.Size(172, 266);

this.treeView1.TabIndex = 2;

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(292, 266);

this.Controls.Add(this.splitter1);

this.Controls.Add(this.treeView1);

this.Controls.Add(this.listBox1);

this.Name = "Form1";

this.Text = "Form1";

this.ResumeLayout(false);

}

#endregion

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main()

{

Application.Run(new Form1());

}

}

}


--



Br,
Mark Broadbent
mcdba , mcse+i
=============
 
P

pronto

Hi All,
C#.
I want create simple not resizable form with List and Tree controls and make
them splittable.
List on left side, Tree on the right side. That's what Splitter for , right
?

How to use splitter in this simple case ?

regards
pronto
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top