Howard Pierce

I have a vertical split SplitContainer inside the top panel of a horizontal split SplitContainer and am trying to set the panel2 min size for it.

I'm getting the following designer error:

SplitterDistance must be between Panel1MinSize and Width - Panel2MinSize.

This is somewhat confusing first of all, since the change was made in the designer. In the first instance therefore, I'm assuming this is a bug in the designer.

The logic of the error message is that SplitterDistance should be between 0 and 560 minus 243 i.e. 317 which at 311 it is.

Has anyone else come across this or have a workaround

//

// splitContainer2

//

this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;

this.splitContainer2.Location = new System.Drawing.Point(0, 0);

this.splitContainer2.Name = "splitContainer2";

//

// splitContainer2.Panel1

//

this.splitContainer2.Panel1.Controls.Add(this.chartGroup);

//

// splitContainer2.Panel2

//

this.splitContainer2.Panel2.Controls.Add(this.capacityGroup);

this.splitContainer2.Panel2MinSize = 243;

this.splitContainer2.Size = new System.Drawing.Size(560, 250);

this.splitContainer2.SplitterDistance = 311;

this.splitContainer2.TabIndex = 5;



Re: Windows Forms Designer SplitContainer Panel MinSize Defect?

Philip Wright

Maybe it also needs to take into account the width of the splitter area. So maybe if the splitter area width is more than the 6 pixels different between the maximum and the value you are supplying then it fails.

Phil Wright
http://www.componentfactory.com
Free UI controls for .NET2





Re: Windows Forms Designer SplitContainer Panel MinSize Defect?

toddwick

I'm hitting this too. smells like a bug in the framework to me!



Re: Windows Forms Designer SplitContainer Panel MinSize Defect?

Martin Thorsen - MSFT

Hi,

Can you give me the exact repro steps. I.e. how are you adding the containers, what sizes are you setting them to, etc.

Thanks

Martin






Re: Windows Forms Designer SplitContainer Panel MinSize Defect?

Syed Atheeque Pasha

Hi

n I am facing the same problem as above

i have created a horiztal splitcontainer with panel1 and Panel2. I used a splitcontainer in the panel2 which divided the panel2 horizontal. when trying to asign the minimum size property of the container2.panel2. i get the following error:

An error occurred creating the form. See Exception.InnerException for details. The error is: SplitterDistance must be between Panel1MinSize and Width - Panel2MinSize.

'SplitContainer2

'

Me.SplitContainer2.Dock = System.Windows.Forms.DockStyle.Fill

Me.SplitContainer2.FixedPanel = System.Windows.Forms.FixedPanel.Panel2

Me.SplitContainer2.IsSplitterFixed = True

Me.SplitContainer2.Location = New System.Drawing.Point(13, 0)

Me.SplitContainer2.Margin = New System.Windows.Forms.Padding(0)

Me.SplitContainer2.Name = "SplitContainer2"

'

'SplitContainer2.Panel1

'

Me.SplitContainer2.Panel1.Controls.Add(Me.SplitContainer3)

Me.SplitContainer2.Panel1.Padding = New System.Windows.Forms.Padding(0, 0, 3, 0)

'

'SplitContainer2.Panel2

'

Me.SplitContainer2.Panel2.Controls.Add(Me.GroupBox3)

Me.SplitContainer2.Panel2.Controls.Add(Me.Panel3)

Me.SplitContainer2.Size = New System.Drawing.Size(866, 538)

Me.SplitContainer2.SplitterDistance = 457

Me.SplitContainer2.SplitterWidth = 7

Me.SplitContainer2.TabIndex = 0

'

'SplitContainer3

'

Me.SplitContainer3.Dock = System.Windows.Forms.DockStyle.Fill

Me.SplitContainer3.FixedPanel = System.Windows.Forms.FixedPanel.Panel1

Me.SplitContainer3.Location = New System.Drawing.Point(0, 0)

Me.SplitContainer3.Margin = New System.Windows.Forms.Padding(0)

Me.SplitContainer3.Name = "SplitContainer3"

'

'SplitContainer3.Panel1

'

Me.SplitContainer3.Panel1.Controls.Add(Me.GroupBox1)

Me.SplitContainer3.Panel1.Controls.Add(Me.Panel1)

Me.SplitContainer3.Panel1MinSize = 0

'

'SplitContainer3.Panel2

'

Me.SplitContainer3.Panel2.Controls.Add(Me.GroupBox2)

Me.SplitContainer3.Panel2.Controls.Add(Me.Panel2)

Me.SplitContainer3.SplitterDistance = 150

Me.SplitContainer3.Panel2MinSize = 250

Me.SplitContainer3.Size = New System.Drawing.Size(454, 538)

Me.SplitContainer3.SplitterIncrement = 10

Me.SplitContainer3.SplitterWidth = 10

Me.SplitContainer3.TabIndex = 0






Re: Windows Forms Designer SplitContainer Panel MinSize Defect?

Martin Thorsen - MSFT

The problem is caused by the fact that setting Panel2MinSize causes the SpiltterDistance to be set and the latter uses the width and height of the container in its calculations. The issue is that the size is not set after the MinSizes (check out InitializeComponent) and thus the default size (150,100) is used which causes the splitterdistance to be negative and we throw.

I have opened a bug on this internally.

There's a couple of workarounds:

1. Move the line that sets the container size in InitializeComponent before the lines that set the min sizes. This is not recommended since this change will be lost the next time InitializeComponent is generated.

2. Hook an event and set the min sizes there. Say the form's load event.

Martin






Re: Windows Forms Designer SplitContainer Panel MinSize Defect?

Eagle 101

Thanks for the clear two choices. I hate UI design and I am glad that this solution could be found quickly! Again many thanks!





Re: Windows Forms Designer SplitContainer Panel MinSize Defect?

bryhhh

Any update on this issue yet I've not found any sign of a hotfix to address this, and the formload event workaround doesn't work for me, so I have to manually swap the lines around in InitializeComponent() after every minor tweak to the form in the IDE.




Re: Windows Forms Designer SplitContainer Panel MinSize Defect?

Howard Pierce

I don't think that MS are in the habit of hotfixing VS. You'll have to wait for the service pack, if there is one.

I must say in the strongest terms that this is long overdue, VS 2005 is considerably less stable than it's predecessor and contains a number of defects that are very detrimental to productivity, particularly with the C# WinForms designer. Although to be fair, we do use 3rd party UI components (ChartFX/DevX) and it is not clear whether the instability stems from them or the IDE. On the basis of other defects that are definitely not 3rd party, I know where I'd put my money.

I'd also like to thank the person who decided that the solution explorer should not synchronise with the currently active document as per 2003. This is a genuine pain in the rear.

My company is currently working on 2 projects: on in VB2003 and one in C#2005. While some of the new features in 2005 are spectacular (in particular the refactoring tools), based on my experience with it so far I would argue against any new projects or the migration of existing projects to 2005 until it is patched.

Put simply, it is still faster for us to develop in 2003, with the possible exception of medium to large scale refactoring. But as I understand, refactoring is not available in VB2005 anyways so......

p.s. apologies for the tangential rant but when you spend as much money as I have on MSDN Univ. licenses I'm sure you'd feel the same.





Re: Windows Forms Designer SplitContainer Panel MinSize Defect?

Howard Pierce

Apologies, found the option that synchs active document with solution explorer



Re: Windows Forms Designer SplitContainer Panel MinSize Defect?

JustAnAverageJoe

Hey Martin, since you've figured out how to bypass the problem, how about you take all that rich knowledge and go impress the makers of the product by publishing a fix for it so we can download it

Someone tell me why we're supposed to pay for this kind of tool with a somewhat psychotic behavior I thought I did something wrong by golly, for a very long time (15 minutes to someone with ADD is an eternity). Can I bill MS for 15 wasted minutes and for the subsequent amount of time it requires for me to restrain the psychotic IDE from throwing crazy exceptions






Re: Windows Forms Designer SplitContainer Panel MinSize Defect?

OmidQRose

Howard Pierce wrote:

for us to develop in 2003, with the possible exception of medium to large scale refactoring. But as I understand, refactoring is not available in VB2005 anyways so......

It is available and even more visualized than cs refactoring unless you meant the built-in one.

VB2005 refactor url: http://www.devexpress.com/vbrefactor/





Re: Windows Forms Designer SplitContainer Panel MinSize Defect?

Howard Pierce

Thanks Omid, I'm a DevX devotee but I hadn't picked up on that product.



Re: Windows Forms Designer SplitContainer Panel MinSize Defect?

Jake Montgomery

Ok, here is a quick workaround that I wrote. Simply use the control SplitContainerFix, provided below, in place of SplitContainer, and the problem should go away. It worked for me.

Use the code however you like, though I make no claims and take no responsibility for any harm that results (may cause tsunamis etc.)

========== Code below

using System;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;

/// <summary>
/// This class is a workaround for a known VS2005 SplitContainer bug.
/// The designer will set Panel2MinSize before setting the control Size,
/// and this causes a exception to be thrown.
/// The solution used here is to store the Panel2MinSize and set it in after the size is set.
/// Use this code at your own risk, as I make no warrenty of any kind.
/// You are free to use this code however you like.
/// </summary>
class SplitContainerFix : SplitContainer
{
public SplitContainerFix()
{
panel2MinSize = base.Panel2MinSize;
}

public new int Panel2MinSize
{
get
{
if (isSized)
return base.Panel2MinSize;
return panel2MinSize;
}
set
{
panel2MinSize = value;
if (isSized)
base.Panel2MinSize = panel2MinSize;
}
}

public new Size Size
{
get {return base.Size;}
set
{
base.Size = value;
if (!isSized)
{
isSized = true;
if (panel2MinSize != 0)
Panel2MinSize = panel2MinSize;
}
}
}

private int panel2MinSize;
private bool isSized = false;
}






Re: Windows Forms Designer SplitContainer Panel MinSize Defect?

Howard Pierce

Has this issue not been resolved by Service Pack 1