locked
Docking and Anchoring on a Windows Form application. RRS feed

  • Question

  • Hello!

    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?

    Thank you.

    Wednesday, November 4, 2009 2:19 PM

Answers

  • Hi,

    tr this:

    upperPanel.Dock = Top;

    bottomPanel.Dock = Bottom;


    (Or)

    set the anchor property to right, left, bottom, right for both controls.


    Regards,
    Malleswar
     
    • Marked as answer by ZHE ZHAO Tuesday, November 10, 2009 3:15 AM
    Wednesday, November 4, 2009 2:59 PM
  • Hello,

    When you have multiple controls that dock in such a way that they potentially overlap each other (as you do here), Visual Studio processes the controls from the "backmost" control to the "frontmost" control. There are two ways your two panels could be processed:

    1. If upperPanel is behind bottomPanel, then upperPanel will be processed first and will be docked to fill the entire form. Then bottomPanel will be processed and will be docked to the bottom of the form, overlapping upperPanel.

    2. If bottomPanel is behind upperPanel then bottomPanel will be processed first and will be docked to the bottom of the form. Then upperPanel will be processed and docked to the remaining form area, which will then fill in the space above bottomPanel, with no overlapping occurring.

    It sounds as if case 1 is occurring in your form, whereas you actually want case 2.

    To cure this, open the form designer, click on upperPanel and then select Format / Order / Bring to Front in the menu. You should find that upperPanel now resizes so that it no longer overlaps bottomPanel.

    Hope that helps!

    Adam.
    www.adamdawes.com
    www.icangames.com
    • Proposed as answer by adamdawes.com Thursday, November 5, 2009 7:17 PM
    • Marked as answer by ZHE ZHAO Tuesday, November 10, 2009 3:15 AM
    Wednesday, November 4, 2009 3:16 PM

All replies

  • Do you get the same result if you set the bottomPanel to dock to the bottom before setting the upperPanel to dock to fill?

    Wednesday, November 4, 2009 2:33 PM
  • Hi,

    tr this:

    upperPanel.Dock = Top;

    bottomPanel.Dock = Bottom;


    (Or)

    set the anchor property to right, left, bottom, right for both controls.


    Regards,
    Malleswar
     
    • Marked as answer by ZHE ZHAO Tuesday, November 10, 2009 3:15 AM
    Wednesday, November 4, 2009 2:59 PM
  • Hello,

    When you have multiple controls that dock in such a way that they potentially overlap each other (as you do here), Visual Studio processes the controls from the "backmost" control to the "frontmost" control. There are two ways your two panels could be processed:

    1. If upperPanel is behind bottomPanel, then upperPanel will be processed first and will be docked to fill the entire form. Then bottomPanel will be processed and will be docked to the bottom of the form, overlapping upperPanel.

    2. If bottomPanel is behind upperPanel then bottomPanel will be processed first and will be docked to the bottom of the form. Then upperPanel will be processed and docked to the remaining form area, which will then fill in the space above bottomPanel, with no overlapping occurring.

    It sounds as if case 1 is occurring in your form, whereas you actually want case 2.

    To cure this, open the form designer, click on upperPanel and then select Format / Order / Bring to Front in the menu. You should find that upperPanel now resizes so that it no longer overlaps bottomPanel.

    Hope that helps!

    Adam.
    www.adamdawes.com
    www.icangames.com
    • Proposed as answer by adamdawes.com Thursday, November 5, 2009 7:17 PM
    • Marked as answer by ZHE ZHAO Tuesday, November 10, 2009 3:15 AM
    Wednesday, November 4, 2009 3:16 PM