Win Form Splitter use tips and tricks
- 2020-05-05 11:44:58
- OfStack
Today, I made an analysis of html code, and then downloaded a batch of procedures, which used Splitter (split bar), compiled the program, found that the split bar did not work, drag the split bar, the adjacent two Panel did not change the size. It took almost a day to figure out why. Including testing on other machines.
Later, we did a completely separate test and found that the use of Splitter had an bug problem, if you first put two Panel and then one Splitter . (note the sequence at this point) and that leads to the problem I had up there. The InitializeComponent function part of the code is as follows:
Note: this is the order in the code. At this point, the execution of the program is problematic. The separator bar will not work.
But if you put the three controls in the following order, it's fine.
1. Put an Panel such as panel1 and set his Dock property as Left;
2. Put an Splitter for example: splitter1 set its background color as a special color to facilitate the execution effect;
3. Put an Panel such as panel2 and set his Dock property as Fill;
4, compile the execution program, at this point there is no problem.
The correct code is :( InitializeComponent function)
Later, we did a completely separate test and found that the use of Splitter had an bug problem, if you first put two Panel and then one Splitter . (note the sequence at this point) and that leads to the problem I had up there. The InitializeComponent function part of the code is as follows:
private void InitializeComponent()
{
//
// ... Other code
//
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();
//
// ... Other code
//
//
// 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 = " Site download tool 2003 years 9 month 21 day ";
this.panel2.ResumeLayout(false);
this.ResumeLayout(false);
}
Note: this is the order in the code. At this point, the execution of the program is problematic. The separator bar will not work.
But if you put the three controls in the following order, it's fine.
1. Put an Panel such as panel1 and set his Dock property as Left;
2. Put an Splitter for example: splitter1 set its background color as a special color to facilitate the execution effect;
3. Put an Panel such as panel2 and set his Dock property as Fill;
4, compile the execution program, at this point there is no problem.
The correct code is :( InitializeComponent function)
private void InitializeComponent()
{
//
// ... Other code
//
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();
//
// ... Other code
//
//
// 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 = " Site download tool 2003 years 9 month 21 day ";
this.Load += new System.EventHandler(this.Form1_Load);
this.panel2.ResumeLayout(false);
this.ResumeLayout(false);
}