Technology: C#, Winforms
The Background:
I have the following container structure (Form containing a panel, which contains 2 panels)
Form F1
|-> Panel P1 (DockStyle.Fill)
|-> Panel P2 (DockStyle.Top)
|-> Panel P3 (DockStyle.Fill)
I register for P3.SizeChange event and in the event I change P2.Size
The Problem:
I expect all the size changes will be reflected correctly on the GUI
Observed result:
Every time P2.Size changes based on the previously set Size
What I have tried:
- I have tried calling PerformLayout and Invalidate, but still the GUI does not correctly reflect the changes.
- If I hook up the same function to F1.SizeChange, it all works fine
- Instead of changing the Size, if I change and revert the DockStyle (P3.Dock = DockStyle.None; P3.Dock = DockStyle.Fill), it messes up the GUI
Seems like in Forms library I cannot change a layout related property (Size, Dock, etc) from a sibling control’s layout related event (SizeChanged)
Has anyone else encountered this issue and have a workaround?
I am using .NET 4.0 (I think) from Visual Studio Express 2010
Inputs will be greatly appreciated
Try changing the size in the next message loop iteration (which will happen after the layout pass ends) by doing it in
BeginInvoke().