Search code examples
c#windows-mobileanchordockinggui-designer

Docking and Anchoring on a Windows Form application


I'm developing an app for Windows Mobile 5.0 and above, with C# and .NET Compact Framework 2.0 SP2.

I have a WinForm with two panels inside (upperPanel and bottomPanel). I want that upperPanel always fill 2/3 of form's height, and bottomPanel fills 1/3 of form's height. Both panels will fill completly form's width.

I've used this:

upperPanel.Dock = Fill;
bottomPanel.Dock = Bottom;

But upperPanel fills the form completly.

How can I do this? I want, more o less, the same gui on differents form factors and on landscape or protrait mode.

Thank you.


Solution

  • What you need to do is to put the bottom panel on first and set its Dock property to Bottom. Then set the panel's height to be 1/3 of the form's height. Finally, add a second panel and set its Dock property to Fill. The key here is that you want to add the control that will fill the remaining area to be added last. Alternatively, you can play around with the Bring to Front and Send to Back commands in Visual Studio to get the designer to cooperate.

    You may also need to hook the OnSizeChanged event for the form and re-set the height of the bottom panel to account for layout changes. It's been a little while since I did compact framework programming, so I'm not sure.