views:

129

answers:

1

I have the following structure in a Windows Form:

Form (AutoResize = true, AutoSizeMode = GrowAndShrink)
    FlowLayout (AutoResize = true, AutoSizeMode = GrowAndShrink)
        GroupBox
        GroupBox
        GroupBox
    StatusStrip

My expectation is that changing the visibility of the GroupBoxes should cause the Window to snap to a new size to reclaim empty space, or accommodate new controls. However, this doesn't happen automatically. If I minimise to the tray and then restore the form (i.e. toggle Visible, ShowInTaskbar, WindowState = Normal/Minimized), then when it reappears, it will have updated correctly. Another thing that triggers it is an update to content in a StatusStrip at the bottom of the page (showing a label, changing a progress bar etc). I've tried various voodoo-inspired combinations of Invalidate/Update/OnResize etc, but I feel I'm missing something a bit more fundamental and hope somebody can see the obvious flaw in what I'm describing.

All my updates to widgets on the form are inside InvokeRequired/Invoke, if that's relevant.

+1  A: 

I can't repro this problem with a simple test form that uses your layout and property settings. The form's client area is shrunk at start-up and grows as needed to make the group box visible when I set its Visible property to true.

You can ask for an explicit layout recalculation with the PerformLayout() method.

Hans Passant
PerformLayout() does the trick! Thank you. :)
Thom