代码
/*splitter控件一定要设置成为top或bottom 与上面的或下面的控件Dock一致才有效果。
而且一定要注意这三个控件的拖入顺序。1.panel1,2.splitter,3.panel2.一定要保证splitter在中间拖入,是VS2005的小BUG吧。
*
* Splitter 控件可以在运行时调整停靠到 Splitter 控件边缘的控件的大小。窗体布局有些麻烦,需要实践中才会明白。现说明窗体分左右和上左右的两种情况。
第一种:窗体分左右两块。 先拖拽一个treeView,设置其Dock属性为Left,再拖拽一个Splitter,设置其Dock属性为Left(默认情况下),最后拖拽一个listView,设置其Dock属性为Fill,OK成功。
第二种:窗体分上左右三块。 先拖拽一个toolBar,设置其Dock属性为Top,再拖拽一个treeView,设置其Dock属性为Left,再拖拽一个Splitter,设置其Dock属性为Left,最后拖拽一个listView,设置其Dock属性为Fill,OK成功。有时需要设置toolBar为置于底层,listView(Dock属性为Fill的控件)为置于顶层。如果不这样,Splitter控件会将窗体分为2半,一半是treeView,一半是toolBar和listView。
Splitter 必然要和拆分的两个控件中之一的Dock属性一样,另一个控件的Dock属性必须是Fill,最好将其置于顶层。
*/
而且一定要注意这三个控件的拖入顺序。1.panel1,2.splitter,3.panel2.一定要保证splitter在中间拖入,是VS2005的小BUG吧。
*
* Splitter 控件可以在运行时调整停靠到 Splitter 控件边缘的控件的大小。窗体布局有些麻烦,需要实践中才会明白。现说明窗体分左右和上左右的两种情况。
第一种:窗体分左右两块。 先拖拽一个treeView,设置其Dock属性为Left,再拖拽一个Splitter,设置其Dock属性为Left(默认情况下),最后拖拽一个listView,设置其Dock属性为Fill,OK成功。
第二种:窗体分上左右三块。 先拖拽一个toolBar,设置其Dock属性为Top,再拖拽一个treeView,设置其Dock属性为Left,再拖拽一个Splitter,设置其Dock属性为Left,最后拖拽一个listView,设置其Dock属性为Fill,OK成功。有时需要设置toolBar为置于底层,listView(Dock属性为Fill的控件)为置于顶层。如果不这样,Splitter控件会将窗体分为2半,一半是treeView,一半是toolBar和listView。
Splitter 必然要和拆分的两个控件中之一的Dock属性一样,另一个控件的Dock属性必须是Fill,最好将其置于顶层。
*/
代码
public partial class FormStart : Form
{
TreeView treeView1 = new TreeView();
ListView listView1 = new ListView();
Splitter splitter1 = new Splitter();
ToolTip tt = new ToolTip();
Label l = new Label();
public FormStart()
{
InitializeComponent();
}
private void CreateMySplitControls()
{
treeView1.Dock = DockStyle.Left;
splitter1.Dock = DockStyle.Left;
//splitter1.MinExtra = 100;
//splitter1.MinSize = 75;
splitter1.Width = 10;
splitter1.Height = 300;
l.Text = "3";
//l.AutoSize = true;
l.Location = new Point(-6, splitter1.Height / 2 - l.Height);
l.Font = new System.Drawing.Font("Marlett", 14, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, (byte)3);
l.ForeColor = Color.Red;
l.Cursor = Cursors.Hand;
splitter1.Controls.Add(l);
listView1.Dock = DockStyle.Fill;
treeView1.Nodes.Add("TreeView Node");
listView1.Items.Add("ListView Item");
tt.SetToolTip(l, "隐藏左边的的控件");
l.Click += new EventHandler(ShowHide);
splitter1.Resize += new EventHandler(splitter_Resize);
this.Controls.AddRange(new Control[] { listView1, splitter1, treeView1 });
}
private void FormStart_Load(object sender, EventArgs e)
{
CreateMySplitControls();
}
private void ShowHide(object sender, EventArgs e)
{
if (l.Text == "3")
{
l.Text = "4";
tt.SetToolTip(l, "显示左边的的控件");
treeView1.Visible = false;
}
else
{
l.Text = "3";
tt.SetToolTip(l, "隐藏左边的的控件");
treeView1.Visible = true;
}
}
private void splitter_Resize(object o, EventArgs e)
{
l.Location = new Point(-6, splitter1.Height / 2 - l.Height);
}
}
{
TreeView treeView1 = new TreeView();
ListView listView1 = new ListView();
Splitter splitter1 = new Splitter();
ToolTip tt = new ToolTip();
Label l = new Label();
public FormStart()
{
InitializeComponent();
}
private void CreateMySplitControls()
{
treeView1.Dock = DockStyle.Left;
splitter1.Dock = DockStyle.Left;
//splitter1.MinExtra = 100;
//splitter1.MinSize = 75;
splitter1.Width = 10;
splitter1.Height = 300;
l.Text = "3";
//l.AutoSize = true;
l.Location = new Point(-6, splitter1.Height / 2 - l.Height);
l.Font = new System.Drawing.Font("Marlett", 14, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, (byte)3);
l.ForeColor = Color.Red;
l.Cursor = Cursors.Hand;
splitter1.Controls.Add(l);
listView1.Dock = DockStyle.Fill;
treeView1.Nodes.Add("TreeView Node");
listView1.Items.Add("ListView Item");
tt.SetToolTip(l, "隐藏左边的的控件");
l.Click += new EventHandler(ShowHide);
splitter1.Resize += new EventHandler(splitter_Resize);
this.Controls.AddRange(new Control[] { listView1, splitter1, treeView1 });
}
private void FormStart_Load(object sender, EventArgs e)
{
CreateMySplitControls();
}
private void ShowHide(object sender, EventArgs e)
{
if (l.Text == "3")
{
l.Text = "4";
tt.SetToolTip(l, "显示左边的的控件");
treeView1.Visible = false;
}
else
{
l.Text = "3";
tt.SetToolTip(l, "隐藏左边的的控件");
treeView1.Visible = true;
}
}
private void splitter_Resize(object o, EventArgs e)
{
l.Location = new Point(-6, splitter1.Height / 2 - l.Height);
}
}
Form1.Designer.cs
代码
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.splitter1);
this.Controls.Add(this.panel1);
this.Controls.Add(this.panel2);
this.Name = "Form1";
this.Text = "Form1";
this.panel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
this.panel2.PerformLayout();
this.ResumeLayout(false);
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.splitter1);
this.Controls.Add(this.panel1);
this.Controls.Add(this.panel2);
this.Name = "Form1";
this.Text = "Form1";
this.panel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
this.panel2.PerformLayout();
this.ResumeLayout(false);
Windows字体的字符运用。。。。
Marlett 字体往上写“5”(向上箭头)、写“6”(向下箭头)就行了(事实上 Windows 所有窗口的关闭、最大化、最小化、恢复、帮助、上下左右箭头都是用 Marlett 字体画上去的,系统御用);
代码
private void Form2_Load(object sender, EventArgs e)
{
//splitter1.MinExtra = 800;
//splitter1.MinSize = 75;
splitter1.Width = 800;
splitter1.Height = 15;
l.Text = "5"; //写入的字,具体指示到符号的不同。。比如3为左箭头,4为右箭头。
//l.AutoSize = true;
//l.Location = new Point( 200 , 50);
l.Font = new System.Drawing.Font("marlett", 14, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (byte)14);
l.ForeColor = Color.Red;
l.Cursor = Cursors.Hand;
splitter1.Controls.Add(l);
}
{
//splitter1.MinExtra = 800;
//splitter1.MinSize = 75;
splitter1.Width = 800;
splitter1.Height = 15;
l.Text = "5"; //写入的字,具体指示到符号的不同。。比如3为左箭头,4为右箭头。
//l.AutoSize = true;
//l.Location = new Point( 200 , 50);
l.Font = new System.Drawing.Font("marlett", 14, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (byte)14);
l.ForeColor = Color.Red;
l.Cursor = Cursors.Hand;
splitter1.Controls.Add(l);
}