Win Form's Splitter using tips and tricks _c# Tutorial

Source: Internet
Author: User
Today, an analysis of the HTML code, and then bulk download the program, where the use of Splitter (split), compiled programs, found that the partition bar does not work, drag the split bar, adjacent to the two Panel does not change size. It took almost a day for this and no reason to find it. Include testing on other machines.
Later, as a completely independent test project, found that the use of Splitter is a bug problem, if you first put two Panel, and then put a Splitter. (Note the order at this point) will cause problems that arise on me. The InitializeComponent function in the code is now part of the code as follows:
Copy Code code 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 September 21, 2003";
This.panel2.ResumeLayout (FALSE);
This. ResumeLayout (FALSE);
}

Note: The order in the code at this time. At this time, the implementation of the program is problematic. The separator bar will not work.
But if you put these three controls in the order you changed them to the following order, there is no problem.
1, put in a Panel for example: Panel1 then set his Dock property to: left;
2, put in a Splitter for example: Splitter1 set its background color for a special color, easy to see the implementation effect;
3, put in a Panel such as: Panel2 then set his Dock property is: Fill;
4, compile the execution program, this time there is no problem.
At this point the correct code should be: (InitializeComponent function part)
Copy Code code 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 (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 September 21, 2003";
This. Load + = new System.EventHandler (this. Form1_Load);
This.panel2.ResumeLayout (FALSE);
This. ResumeLayout (FALSE);
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.