Search code examples
c#winformssplitcontainer

SplitterDistance Property won't get smaller than 25 pixels


I have a split container within a split container, and when I set the SplitterDistance to anything less than 25 pixels, the SplitterDistance will not get smaller. I can make it smaller than 25 pixels during run-time with no problem. I can make it larger via the code or designer and during run-time no problem. I want to set it to about 20 pixels, without the user having to re-size it. Does anyone know why it keeps reverting to 25 pixels, and if there is anyway to get it less than that?

I tried this and it doesn't work:

        // 
        // splitContainer3
        // 
        this.splitContainer3.Dock = System.Windows.Forms.DockStyle.Fill;
        this.splitContainer3.Location = new System.Drawing.Point(0, 0);
        this.splitContainer3.Name = "splitContainer3";
        this.splitContainer3.Orientation = System.Windows.Forms.Orientation.Horizontal;
        // 
        // splitContainer3.Panel1
        // 
        this.splitContainer3.Panel1.RightToLeft = System.Windows.Forms.RightToLeft.No;
        this.splitContainer3.Panel1MinSize = 5;
        // 
        // splitContainer3.Panel2
        // 
        this.splitContainer3.Panel2.Controls.Add(this.txtLineNums);
        this.splitContainer3.Panel2.RightToLeft = System.Windows.Forms.RightToLeft.No;
        this.splitContainer3.Panel2MinSize = 5;
        this.splitContainer3.RightToLeft = System.Windows.Forms.RightToLeft.No;
        this.splitContainer3.Size = new System.Drawing.Size(47, 562);
        this.splitContainer3.SplitterDistance = 20;
        this.splitContainer3.SplitterWidth = 2;
        this.splitContainer3.TabIndex = 0;
        this.splitContainer3.TabStop = false;

Thanks!


Solution

  • Make sure your split container panel MinSizes aren't set too high to go down to 20. The default panel MinSizes are 25. The splitter distance will go as low as it can without encroaching on it.

    Panel sizes are set in the overall split-container properties. You can see this below:

    enter image description here

    Of course, you can always programmatically set them by drilling down into the split-container properties in your code:

    splitContainer1.Panel1MinSize = 0;
    splitContainer1.SplitterDistance = 20;
    

    [Edit]

    Further demonstration shown below:

    enter image description here

    enter image description here