Win Form 的 Splitter 使用心得与技巧
更新时间:2020年6月25日 11:44 点击:2200
今天作个分析html代码,然后再批量下载的程序,其中用到 Splitter (分割条),编译程序后,发现分割条不起作用,拖动分割条的时候,相邻的两个 Panel 没有变换大小。为这个几乎花了一天时间,也没找到原因。包括到其他机子上测试。
后来,再次作一个完全独立的测试项目,发现 Splitter 的使用有个算是 bug 的问题,如果你首先放两个 Panel ,然后再放一个 Splitter 。(注意这时候的次序)就会产生我上面出现的问题。这时候代码中的 InitializeComponent 函数部分代码如下:
private void InitializeComponent()
{
//
// ... 其他代码
//
this.panel1 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel();
this.splitter1 = new System.Windows.Forms.Splitter();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// ... 其他代码
//
//
// panel1
//
this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
this.panel1.Location = new System.Drawing.Point(0, 42);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(120, 209);
this.panel1.TabIndex = 6;
this.panel1.Resize += new System.EventHandler(this.panel2_Resize);
this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel2_Paint);
//
// panel2
//
this.panel2.Controls.Add(this.splitter1);
this.panel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel2.Location = new System.Drawing.Point(120, 42);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(328, 209);
this.panel2.TabIndex = 7;
this.panel2.Resize += new System.EventHandler(this.panel2_Resize);
this.panel2.Paint += new System.Windows.Forms.PaintEventHandler(this.panel2_Paint);
//
// splitter1
//
this.splitter1.BackColor = System.Drawing.SystemColors.Desktop;
this.splitter1.Location = new System.Drawing.Point(0, 0);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(3, 209);
this.splitter1.TabIndex = 0;
this.splitter1.TabStop = false;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.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 函数部分)
private void InitializeComponent()
{
//
// ... 其他代码
//
this.panel1 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel();
this.splitter1 = new System.Windows.Forms.Splitter();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// ... 其他代码
//
//
// panel1
//
this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
this.panel1.Location = new System.Drawing.Point(0, 42);
this.panel1.Name = "panel1";
this.panel1.Size = new System.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 = new System.Drawing.Point(200, 42);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(248, 209);
this.panel2.TabIndex = 7;
//
// splitter1
//
this.splitter1.BackColor = System.Drawing.SystemColors.Desktop;
this.splitter1.Location = new System.Drawing.Point(0, 0);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(3, 209);
this.splitter1.TabIndex = 0;
this.splitter1.TabStop = false;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.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 += new System.EventHandler(this.Form1_Load);
this.panel2.ResumeLayout(false);
this.ResumeLayout(false);
}
后来,再次作一个完全独立的测试项目,发现 Splitter 的使用有个算是 bug 的问题,如果你首先放两个 Panel ,然后再放一个 Splitter 。(注意这时候的次序)就会产生我上面出现的问题。这时候代码中的 InitializeComponent 函数部分代码如下:
复制代码 代码如下:
private void InitializeComponent()
{
//
// ... 其他代码
//
this.panel1 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel();
this.splitter1 = new System.Windows.Forms.Splitter();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// ... 其他代码
//
//
// panel1
//
this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
this.panel1.Location = new System.Drawing.Point(0, 42);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(120, 209);
this.panel1.TabIndex = 6;
this.panel1.Resize += new System.EventHandler(this.panel2_Resize);
this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel2_Paint);
//
// panel2
//
this.panel2.Controls.Add(this.splitter1);
this.panel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel2.Location = new System.Drawing.Point(120, 42);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(328, 209);
this.panel2.TabIndex = 7;
this.panel2.Resize += new System.EventHandler(this.panel2_Resize);
this.panel2.Paint += new System.Windows.Forms.PaintEventHandler(this.panel2_Paint);
//
// splitter1
//
this.splitter1.BackColor = System.Drawing.SystemColors.Desktop;
this.splitter1.Location = new System.Drawing.Point(0, 0);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(3, 209);
this.splitter1.TabIndex = 0;
this.splitter1.TabStop = false;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.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 函数部分)
复制代码 代码如下:
private void InitializeComponent()
{
//
// ... 其他代码
//
this.panel1 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel();
this.splitter1 = new System.Windows.Forms.Splitter();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// ... 其他代码
//
//
// panel1
//
this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
this.panel1.Location = new System.Drawing.Point(0, 42);
this.panel1.Name = "panel1";
this.panel1.Size = new System.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 = new System.Drawing.Point(200, 42);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(248, 209);
this.panel2.TabIndex = 7;
//
// splitter1
//
this.splitter1.BackColor = System.Drawing.SystemColors.Desktop;
this.splitter1.Location = new System.Drawing.Point(0, 0);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(3, 209);
this.splitter1.TabIndex = 0;
this.splitter1.TabStop = false;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.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 += new System.EventHandler(this.Form1_Load);
this.panel2.ResumeLayout(false);
this.ResumeLayout(false);
}
上一篇: C#重启远程计算机的代码
下一篇: C# 多网卡 Server Listen
相关文章
- 本篇文章是对C#中WinForm控件之Dock顺序调整进行了详细的分析介绍,需要的朋友参考下...2020-06-25
- 这篇文章主要介绍了C# Winform中实现主窗口打开登录窗口关闭的方法,这在需要用户名密码的软件项目中是必用的一个技巧,要的朋友可以参考下...2020-06-25
- 下面小编就为大家带来一篇C# winform打开Excel文档的方法总结(必看篇)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
antd Form组件方法getFieldsValue获取自定义组件的值操作
这篇文章主要介绍了antd Form组件方法getFieldsValue获取自定义组件的值操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-10-29- 这篇文章主要给大家介绍C# winform快捷键设置技巧,涉及到C winform快捷键相关知识,对C winform知识感兴趣的朋友可以参考下本篇文章...2020-06-25
c#中Winform实现多线程异步更新UI(进度及状态信息)
本篇文章主要介绍了c#中Winform实现多线程异步更新UI(进度及状态信息) ,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25- 这篇文章主要介绍了C#实现windows form限制文本框输入的方法,涉及C#限制文本框输入的技巧,非常具有实用价值,需要的朋友可以参考下...2020-06-25
- 这篇文章主要介绍了angularjs $http实现form表单提交示例,非常具有实用价值,需要的朋友可以参考下 ...2017-06-15
- 这篇文章主要为大家详细介绍了jquery插表单件form使用方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2017-01-23
- 这篇文章主要给大家介绍了关于c# winform异步不卡界面的实现方法,文中通过示例代码介绍的非常详细,对大家学习或者使用c#具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧...2020-06-25
C# WinForm程序处理后台繁忙导致前台控件假死现象解决方法
这篇文章主要介绍了C# WinForm程序处理后台繁忙导致前台控件假死现象解决方法,本文通过Application.DoEvents()解决这个问题,并讲解了Application.DoEvents()的作用,需要的朋友可以参考下...2020-06-25- 这篇文章主要介绍了C#中winform使用相对路径读取文件的方法,实例分析了C#使用相对路径读取文件的技巧与实际应用,需要的朋友可以参考下...2020-06-25
- 这篇文章主要介绍了解决antd Form 表单校验方法无响应的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-10-28
winform中的ListBox和ComboBox绑定数据用法实例
这篇文章主要介绍了winform中的ListBox和ComboBox绑定数据用法,实例分析了将集合数据绑定到ListBox和ComboBox控件的技巧,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25- 这篇文章主要介绍了C#在Winform开发中使用Grid++报表,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-06-25
- 这篇文章主要为大家详细介绍了C# WinForm程序设计简单计算器,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-06-25
C# WinForm控件对透明图片重叠时出现图片不透明的简单解决方法
这篇文章主要介绍了C# WinForm控件对透明图片重叠时出现图片不透明的简单解决方法,结合实例形式分析了WinForm图片重叠后造成图片不透明的原因与相应的解决方法,需要的朋友可以参考下...2020-06-25- 这篇文章主要介绍了Angular实现form自动布局的相关资料,以代码片段的形式分析了Angular实现form自动布局的实现方法,感兴趣的小伙伴们可以参考一下...2016-02-01
- 在工作中遇到这样一个问题,在系统使用过程中,输入法会变灰导致无法使用输入法输入文字,就好像输入法被禁用了没有启用似的。对此,在这里做个备录...2020-06-25
- 2015年7月29日0点起,Windows 10推送全面开启,Windows7、Windows8.1用户可以免费升级到Windows 10,用户也可以通过系统升级到Windows10,在这过程中,用户会遇到这样那样的问题,下面小编总结了windows 10 安装和使用中5个常见问题,需要的朋友可以参考下...2016-01-27