a common problem
C # WinForms.Net 4.0 Application.
I have a SplitContainer that takes up most of the form, it is anchored in all directions, so it resizes along with the form. The left panel (Panel1) has a simple menu, there are no problems. The right panel (Panel2) is more complex and contains several nested tab controls (with a large number of controls) - it is very complex, but does not change.
The problem is that resizing the form does not work so well. In fact, if you resize by slowly dragging the edges, then this works fine, but drag quickly or use the "restore" button (in the upper right corner of the form), then the problem arises.
My management hierarchy
The following is a simple example of my control hierarchy, this is a definitely truncated version, but it highlights a nested tab control that can help with replication:
- the form
- Split container (anchor: top, left, bottom, right)
- SC Panel1 (Minimum Width: 300)
- TreeViewControl (forget what it's called)
- SC Panel2
- Panel (anchor: top, left, bottom, right)
- Tab management (snap: top, left, bottom, right)
- Managing tabs with a large number of pages that go beyond the screen and require that the navigation buttons appear in the upper right corner (snap: top, left, bottom, right)
Debug Details
After some debugging, it turns out that in fact, Panel2 (a child of a split container) is not the SplitContainer properly, but the SplitContainer itself changes the SplitContainer normally.
Here are the debug values โโthat show this ...
Full width of the form, before resizing:
splitContainerMain.Width: 1479 splitContainerMain.Panel2.Width: 1206 panelCenter.Width: 1203 tabControlMain.Width: 1215
All, as expected, splitContainerMain.Panel2.Width smaller than splitContainerMain.Width .
After resizing, where the problem occurs:
splitContainerMain.Width: 815 splitContainerMain.Panel2.Width: 1206 panelCenter.Width: 1203 tabControlMain.Width: 1215
As you can see, splitContainerMain.Width is optional, but splitContainerMain.Panel2.Width and its children splitContainerMain.Panel2.Width did not.
NOTE Please remember that the width is updated correctly if I slowly resize the form manually - this is not a problem if I incorrectly configure any anchors.
My efforts so far
I tried to use various form resize events and try to set the width manually, but to no avail. I think I would like to try setting the value of Panel2.Width from some event.
What i'm looking for
- Is there anyway to force
splitContainerMain.Panel2.Width to splitContainerMain.Panel2.Width correctly when splitContainerMain is splitContainerMain ? - Also, how can I calculate what
Panel2.Width should be? And how can I set this value from the Form.Resize event? (or another event?)