强制 WinForms AutoResize 发生
我在 Windows 窗体中具有以下结构:
Form (AutoResize = true, AutoSizeMode = GrowAndShrink)
FlowLayout (AutoResize = true, AutoSizeMode = GrowAndShrink)
GroupBox
GroupBox
GroupBox
StatusStrip
我的期望是,更改 GroupBox 的可见性应导致窗口捕捉到新大小以回收空白空间或容纳新控件。然而,这不会自动发生。如果我最小化到托盘然后恢复表单(即切换可见,ShowInTaskbar,WindowState =正常/最小化),那么当它重新出现时,它将正确更新。触发它的另一件事是页面底部 StatusStrip 中内容的更新(显示标签、更改进度条等)。我尝试过各种受巫毒启发的 Invalidate/Update/OnResize 等组合,但我觉得我错过了一些更基本的东西,希望有人能看到我所描述的明显缺陷。
我对表单上小部件的所有更新都在 InvokeRequired/Invoke 内(如果相关的话)。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法使用使用您的布局和属性设置的简单测试表单来重现此问题。当我将其 Visible 属性设置为 true 时,窗体的客户区在启动时缩小并根据需要增大以使组框可见。
您可以使用 PerformLayout() 方法请求显式布局重新计算。
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.