我有一个 flowLayoutPanel 动态填充子控件。此 flowLayoutPanel 可能位于不同表单的某些面板上,因此其大小可能会在运行时发生变化。
添加第一个子控件时,我将其 Width 设置为 flowLayoutPanel.Width - 10。对于其他控件,我设置 DockStyle = Fill。
还有 flowLayoutPanel_Layout 事件处理程序改变了第一个控件的宽度: flowLayoutPanel.Controls[0].Width = flowLayoutPanel.Width - 10;
在大多数情况下,它工作正常,但在其中一个表单上,我遇到了一个问题:加载表单时,flowLayoutPanel 将所有控件的宽度设置为一个值 (127)。当我最大化表单时,使用正确的 flowLayoutPanel.Width(例如,400 像素)调用 flowLayoutPanel_Layout,但是在将其设置为 flowLayoutPanel.Width - 10 后 flowLayoutPanel.Controls[0].Width 没有改变。它仍然等于127. 没有例外或任何事情。
什么会导致这种行为?