开发者

Forcing WinForms AutoResize to happen

I have the following structure in a Wind开发者_Python百科ows 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜