手机
当前位置:查字典教程网 >编程开发 >C#教程 >Win Form 的 Splitter 使用心得与技巧
Win Form 的 Splitter 使用心得与技巧
摘要:今天作个分析html代码,然后再批量下载的程序,其中用到Splitter(分割条),编译程序后,发现分割条不起作用,拖动分割条的时候,相邻的...

今天作个分析html代码,然后再批量下载的程序,其中用到Splitter(分割条),编译程序后,发现分割条不起作用,拖动分割条的时候,相邻的两个Panel没有变换大小。为这个几乎花了一天时间,也没找到原因。包括到其他机子上测试。

后来,再次作一个完全独立的测试项目,发现Splitter的使用有个算是bug的问题,如果你首先放两个Panel,然后再放一个Splitter。(注意这时候的次序)就会产生我上面出现的问题。这时候代码中的InitializeComponent函数部分代码如下:

复制代码 代码如下:

privatevoidInitializeComponent()

{

//

//...其他代码

//

this.panel1=newSystem.Windows.Forms.Panel();

this.panel2=newSystem.Windows.Forms.Panel();

this.splitter1=newSystem.Windows.Forms.Splitter();

this.panel2.SuspendLayout();

this.SuspendLayout();

//

//...其他代码

//

//

//panel1

//

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

this.panel1.Location=newSystem.Drawing.Point(0,42);

this.panel1.Name="panel1";

this.panel1.Size=newSystem.Drawing.Size(120,209);

this.panel1.TabIndex=6;

this.panel1.Resize+=newSystem.EventHandler(this.panel2_Resize);

this.panel1.Paint+=newSystem.Windows.Forms.PaintEventHandler(this.panel2_Paint);

//

//panel2

//

this.panel2.Controls.Add(this.splitter1);

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

this.panel2.Location=newSystem.Drawing.Point(120,42);

this.panel2.Name="panel2";

this.panel2.Size=newSystem.Drawing.Size(328,209);

this.panel2.TabIndex=7;

this.panel2.Resize+=newSystem.EventHandler(this.panel2_Resize);

this.panel2.Paint+=newSystem.Windows.Forms.PaintEventHandler(this.panel2_Paint);

//

//splitter1

//

this.splitter1.BackColor=System.Drawing.SystemColors.Desktop;

this.splitter1.Location=newSystem.Drawing.Point(0,0);

this.splitter1.Name="splitter1";

this.splitter1.Size=newSystem.Drawing.Size(3,209);

this.splitter1.TabIndex=0;

this.splitter1.TabStop=false;

//

//Form1

//

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

this.ClientSize=newSystem.Drawing.Size(448,273);

this.Controls.Add(this.panel2);

this.Controls.Add(this.panel1);

this.Controls.Add(this.toolBar1);

this.Controls.Add(this.statusBar1);

this.Name="Form1";

this.Text="站点下载工具2003年9月21日";

this.panel2.ResumeLayout(false);

this.ResumeLayout(false);

}

注意:这时候的代码中的顺序。这时候,程序的执行是有问题的。分隔条会不起作用。

但是如果你把这三个控件放入顺序修改为下面的顺序就没有问题了。

1、放入一个Panel比如:panel1然后设置他的Dock属性为:Left;

2、放入一个Splitter比如:splitter1设置它的背景颜色为一个特殊的颜色,便于看执行效果;

3、放入一个Panel比如:panel2然后设置他的Dock属性为:Fill;

4、编译执行程序,这时候就没有问题了。

这时候正确的代码应该是:(InitializeComponent函数部分)

复制代码 代码如下:

privatevoidInitializeComponent()

{

//

//...其他代码

//

this.panel1=newSystem.Windows.Forms.Panel();

this.panel2=newSystem.Windows.Forms.Panel();

this.splitter1=newSystem.Windows.Forms.Splitter();

this.panel2.SuspendLayout();

this.SuspendLayout();

//

//...其他代码

//

//

//panel1

//

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

this.panel1.Location=newSystem.Drawing.Point(0,42);

this.panel1.Name="panel1";

this.panel1.Size=newSystem.Drawing.Size(200,209);

this.panel1.TabIndex=6;

//

//panel2

//

this.panel2.Controls.Add(this.splitter1);

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

this.panel2.Location=newSystem.Drawing.Point(200,42);

this.panel2.Name="panel2";

this.panel2.Size=newSystem.Drawing.Size(248,209);

this.panel2.TabIndex=7;

//

//splitter1

//

this.splitter1.BackColor=System.Drawing.SystemColors.Desktop;

this.splitter1.Location=newSystem.Drawing.Point(0,0);

this.splitter1.Name="splitter1";

this.splitter1.Size=newSystem.Drawing.Size(3,209);

this.splitter1.TabIndex=0;

this.splitter1.TabStop=false;

//

//Form1

//

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

this.ClientSize=newSystem.Drawing.Size(448,273);

this.Controls.Add(this.panel2);

this.Controls.Add(this.panel1);

this.Controls.Add(this.toolBar1);

this.Controls.Add(this.statusBar1);

this.Menu=this.mainMenu1;

this.Name="Form1";

this.Text="站点下载工具2003年9月21日";

this.Load+=newSystem.EventHandler(this.Form1_Load);

this.panel2.ResumeLayout(false);

this.ResumeLayout(false);

}

【Win Form 的 Splitter 使用心得与技巧】相关文章:

分享C#操作内存读写方法的主要实现代码

Winform跨线程操作的简单方法

c#创建Graphics对象的三种方法

深入HTTP head的使用详解

C#的四个基本技巧

winform调用javascript的小例子

WinForm窗体调用WCF服务窗体卡死问题

WinForm中的登录实现

C# Dictionary的使用实例代码

.net C# 实现任意List的笛卡尔乘积算法代码

精品推荐
分类导航