Win Form 的 Splitter 使用心得与技巧

2016-02-19 11:11 50 1 收藏

想不想get新技能酷炫一下,今天图老师小编就跟大家分享个简单的Win Form 的 Splitter 使用心得与技巧教程,一起来看看吧!超容易上手~

【 tulaoshi.com - 编程语言 】

今天作个分析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); 

来源:https://www.tulaoshi.com/n/20160219/1596711.html

延伸阅读
标签: 游戏动漫
《机战Z3 天狱篇》角色使用心得与技能学习 磨磨蹭蹭终于也通关了。先说说最终话,这关真的要4回合才能过。一开始的胜利条件是敌全灭,好吧,boss还没到场一回合足够了。然后胜利变成迎来第4回合...啊喂,排队上大号也不用3个回合啊...这是要在最后向战术待机致敬么?第4回合boss带着一帮小弟终于来了,直接MAP扫掉,,摸几下boss还会增援12个 7...
《刀塔传奇》各英雄使用心得技巧 对于玩过的dota玩家来说,《刀塔传奇》里面各种英雄的技能可能相对比较熟悉,实际游戏欧忠对于阵容搭配可能更加有想法,下面是关于游戏英雄使用心得技巧,新手玩家可以学习一下。 英雄使用心得技巧 小鹿 很萌的小鹿有没有,很萌的配音有没有。 五小强之一,定位是奶妈,位置后排。 冲着小鹿萌萌的声音,...
标签: 办公软件
“邮件合并”是Word的一项高级功能,是办公自动化人员应该掌握的基本技术之一。但是大多数书上对“邮件合并”的介绍都很简单,如果按照书的上介绍去做,合并打印出的邮件并不能完全令人满意。教你几个邮件合并技巧,希望能帮你提高办公效率。 1.用一页纸打印多个邮件 利用Word“邮件合并”可以批量处理和打印邮件,很多情况下我们的...
标签: 摄影 摄影技巧
索尼α6000是2014年第一季度推出的新品,也是索尼自从改变命名规则后推出的第二款微单相机。今天我们来给大家分享下个人的使用心得,给小伙伴们参考下。     也许这个时候写这样一篇文章,会被很多人鄙视。如今的全画幅都已经这么便宜了,还讨论残幅相机有什么意思,更何况A6000连残幅中的旗舰也不是,它甚至还不是单反,区区...
标签: 血源 游戏动漫
《血源》近战武器使用心得技巧分享攻略 《血源》游戏目前右手武器除了镰刀跟怪兽爪以外都拿到了,简单讲一下部分武器使用心得,顺便抛砖引玉,等待真正的高手一起来分享。 1. 锯肉刀 变化前:攻击速度快,攻击方式为连续横砍,非常实用,伤害不算高,但是基本上前期就算不升级都还堪用,因为速度快的关係,过关速度非常流畅,我一开始选这...

经验教程

81

收藏

40
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部