Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested SplitContainers bug the SplitterWidth

So I have 3 split containers, with 2 panels each.

SplitContainer1 is the main container that is docked in the Form ( Parent ).

SplitContainer1.Panel1 contains SplitContainer2 which is docked.

SplitContainer1.Panel2 contains SpliContainer3 which is docked.

So far so good.

SplitContainer1 has a SplitterWidth of 3. SplitContainer2 and SplitContainer3 has a SplitterWidth of 6.

In the Designer, you can see the SplitterWidth difference between them, but when I build the solution, the SplitterWidth of SplitContainer2 and SplitContainer3 gets reset back to 4 no matter what I do. I have changed the code in "InitializeComponent" of the form with no effect.

The only way I got this working is in the Load Event of the form, re-specify the SplitterWidths which I find completely dumb. Why won't the SplitterWidths stay at the value I specified in the Designer?

If anyone can shed some light on this, what would be awesome!!

Thanks for your time,

Peter

like image 955
Peter Avatar asked Nov 09 '14 16:11

Peter


1 Answers

Just so that this isn't left unanswered for eternity -

This is an old bug that has been in Visual Basic for many versions now, and is never addressed (nor is it likely to ever be addressed).

As Hans Passant mentions, the issue is due to the ISupportInitialize implementation for the SplitContainer.

Since it's a bug, there is not definitive way of resolving the issue that makes any logical sense.

One way, which I've tested in a mock up program, is as @xfx says - Add and manipulate the controls programmatically, rather than using the toolbox.

An alternative is to reload the SplitterWidths programatically, whether that's on Form_Load, which is most likely, or anywhere else in the code that it may be required.

like image 147
David Avatar answered Nov 15 '22 04:11

David