Reputation: 495
I've got a flowLayoutPanel which is filled dynamically with child controls. This flowLayoutPanel might be on some panels on different forms, so its size might change in runtime.
When adding the first child control, I set its Width to flowLayoutPanel.Width - 10. For other controls I set DockStyle = Fill.
There is also flowLayoutPanel_Layout event handler hich changes the first control width: flowLayoutPanel.Controls[0].Width = flowLayoutPanel.Width - 10;
For most cases it works fine, but on one of the forms, I've got a problem: when the form is loaded, the flowLayoutPanel sets all controls width to one value (127). When I maximize the form, flowLayoutPanel_Layout is called with correct flowLayoutPanel.Width (for example, something like 400 pixels), but flowLayoutPanel.Controls[0].Width is not changed after setting it to flowLayoutPanel.Width - 10. It still equals to 127. There is no exception or anything.
What can cause such behaviour?
Upvotes: 0
Views: 1400
Reputation: 495
Found the root of the problem: this issue appears on 64-bit Windows Vista and 7 when there are lots of nested controls: http://blogs.msdn.com/b/alejacma/archive/2008/11/20/controls-won-t-get-resized-once-the-nesting-hierarchy-of-windows-exceeds-a-certain-depth-x64.aspx
Overriding OnSizeChanged in my control helped:
protected override void OnSizeChanged(EventArgs e)
{
if (!DesignMode && IsHandleCreated)
BeginInvoke((MethodInvoker)delegate{base.OnSizeChanged(e);});
else
base.OnSizeChanged(e);
}
Upvotes: 2