Windows Develop Bookmark and Share   
 index > Windows Forms Designer > SplitContainer Panel MinSize Defect?
 

SplitContainer Panel MinSize Defect?

I have a vertical split SplitContainer insidethe top panel of a horizontal splitSplitContainer and am trying to set the panel2min 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;

Howard Pierce  Tuesday, April 04, 2006 11:14 AM

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

Martin Thorsen - MSFT  Monday, April 24, 2006 8:47 PM

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

Philip Wright  Thursday, April 13, 2006 7:16 AM
I'm hitting this too. smells like a bug in the framework to me!
toddwick  Wednesday, April 19, 2006 11:36 PM

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

Martin Thorsen - MSFT  Thursday, April 20, 2006 5:43 PM

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

Syed Atheeque Pasha  Friday, April 21, 2006 3:17 AM

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

Martin Thorsen - MSFT  Monday, April 24, 2006 8:47 PM

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

Eagle 101  Wednesday, June 14, 2006 7:13 PM
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.
bryhhh  Tuesday, September 26, 2006 9:32 AM

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 muchmoney as I have on MSDN Univ. licenses I'm sure you'd feel the same.

Howard Pierce  Tuesday, September 26, 2006 10:01 AM
Apologies, found the option that synchs active document with solution explorer
Howard Pierce  Wednesday, September 27, 2006 9:33 AM

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?

JustAnAverageJoe  Tuesday, October 24, 2006 7:06 PM
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 andeven more visualized than cs refactoring unless you meant the built-in one.

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

OmidQRose  Monday, January 08, 2007 11:10 PM
Thanks Omid, I'm a DevX devotee but I hadn't picked up on that product.
Howard Pierce  Tuesday, January 09, 2007 9:57 AM

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;
}


Jake Montgomery  Friday, February 16, 2007 1:50 AM

Has this issue not been resolved by Service Pack 1?

Howard Pierce  Friday, February 16, 2007 10:53 AM
 Howard Pierce wrote:

Has this issue not been resolved by Service Pack 1?



Microsoft did not fix this defect with VS 2005 SP1.
jmt9n  Friday, February 16, 2007 5:54 PM

I am trying to figure out how to include this class in my visual studio project (vb.net - the code has been converted) so all calls for resize to any one of 3 splitcontainers are called appropriately. Two below have vertical orientation and each is contained within the MainDisplay SplitContainer that has a horizontal orientation (actually the orientation changes depending on the way the underlying Panel is divided up. Thanks! -greg

SplitContainer_MainDisplay

SplitContainer_Panes_1_3

SplitContainer_Panes_2_4

hazz  Wednesday, May 02, 2007 7:52 PM

This did it for me:

Left the Min Sizes in the designer as they where (150/2)and set them in the constructor.

public Constructor()

{

InitializeComponent();

this.splitContainer1.Panel1MinSize = 350;

this.splitContainer1.Panel2MinSize = 200;

}

But the hole thing is embarrassing for MS. Fix this, please!

Ulrich

Uli F  Friday, September 07, 2007 9:35 AM

I avoid using SplitContainers and the other "new" container components for this very reason. It's much easier just to lay the panels and splitter out and set the docking properties yourself. Sure, it's an additional 20 seconds of buildout, but it saves you from all the headaches that are the result of dealing withpiddly bugs like this, not to mention the SplitContainer's unintuitive property set.

Brian Schoenbeck  Tuesday, February 19, 2008 4:21 PM
Crazy - I'm in VS2008 and the problem still happens. You'd think they'd fix this by now ... the SplitContainer isn't exactly "new" anymore.
Darrell Bennington  Friday, October 17, 2008 9:39 PM

SkinFeature is a custom skinning implementation library and GUI design tool available as DLL and .NET components. It allows you easily to create skins . this skin creator supports MS Visual C ++MFC(5.0, 6.0, vs2002, vs2003, vs2005, vs2008), MS Visual Basic, Delphi, Windows Forms (.NET), WTL, ATL, ,and all Win32 languages that support COM objects. The SkinFeature GUI design tool offers flexible controls customization for all Windows elements.

This IS Visual Skin Builder Tool

skin preview:


SkinFeature developer library improves the visual appearance of your applications by adding originality and uniqueness.

SkinFeature developer library is a powerful library that changes the visual appearance of windows or dialogs, providing developers with full-featured support for 'application skins', or 'application look and feel'. Skinfeature makes it easy to create programs with visually stunning, fully interactive user interfaces.

When it comes to impressing your clients and your software users, nothing is more helpful than SkinFeature skin creator software. With innovative features and superior simplicity of use, you'll agree that no other GUI design tool comes close.

features:

With SkinFeature you could make your program look exactly like it was from another OS, or create your own user WinAmp-like "skinned" interfaces, or just give it a different, distinctive look.
¦ support all Windows standard control
¦ support Windows 98/NT4/2000/XP/2003
¦ support MFC/WTL/SDK/VB/DELPHI/.NET/WIN32COM
¦ support MDI/SDI/Dialog/Shape style window
¦ support Windows's common dialog
¦ support custom control
¦ support UNICODE
¦ WYSWYG skin editor
¦ include all source

WEBSite: http://www.skinui.com

skinfeature界面换肤组件  Saturday, October 18, 2008 1:43 PM

I'm actually working on a project right now and noticed it as well! I can't believe that MS is this bad at patching something that, to me, should be relatively simple.

All they need to do is change where it places the overall container code to before the panel code, correct?

Just out of curiosity, so I don't destroy my project, could someone please post an example of option 2 of what Martin Thorsen mentioned in his post... "Hook an event and set the min sizes there. Say the form's load event."

Thank you,

~ Kyle

HBS TechTeam  Friday, October 31, 2008 5:33 PM
I hope this is not too late for you.
This issue has been open since at least March 2006 and probably earlier, so 13 days more is not much to wait :-D
You can take the advice of Uli F that sets the Panel minimum sizes after the InitializeComponent() call in the constructor. (The New() method of your form)

Martin Thorsen says to do this in the form's Load event, but why not in the constructor ASAP afterInitializeComponent()

Either way just set the minimum panel sizes in the constructor or Load event, either one.

Since Uli F has posted how to do it in the constructor. I'll do it here in the Load event of the form

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.SplitContainer1.Panel2MinSize = 200
Me.SplitContainer1.Panel1MinSize = 500
End Sub

You will have to make sure that in the designer these two properties are set suitably small. I used the default of 25.
You can set the SplitterDistance and Size.Width properties in the designer. In the example above mine is set to 650 and the overall width of the SplitContainer is 900.



Noonan  Thursday, November 13, 2008 1:21 AM
I have tested this issue in theVS2010 CTP. This bug is still here.
Beketata  Monday, February 16, 2009 6:14 PM
Ulrich

Embarrassing for MS. They are use to it, just look at vista. MS does not care.

They already have your money and have most of the market. .net should never have been adopted but it was and we are stuck using it.

Just wait, they probably already planed the deprication of the language.

I have never liked Microsoft or their business practices, but I have made a lot of money rewriting software every time they reinvent the wheel.
Michael Pollack  Friday, April 03, 2009 10:46 PM
Well, I've hit this bug and many others using VS 2008, and my code is beginning to suffer as a result of Microsoft's bugs. I'll be switching to C++ after my current project wraps up; no more Microsoft stuff for me.
Lowkus  Thursday, April 09, 2009 8:45 AM

You can use google to search for other answers

Custom Search

More Threads

• BUG?! Visual Studio .NET 2003: Why is a Modal Dialog destroyed?
• How designer "abstract" bug can be fixed for UserControls?
• Panel has thrown an unhandled exception in the designer and has been disabled.
• Hide certain standard control's properties from designer
• Bold font in TreeView
• Mouse monitoring.(monitoring key Clicks)
• ًWindows appliction themes and skins
• Custom ExpandableObjectConverter to show the contents of the selected Control
• Auto generating buttons
• Winforms control appearance is different in the Visual Studio form designer than at run time. .Net3.5 C#