Search code examples
delphivcl

Can I alter control layout on the fly?


Is there a way to alter a window or dialog from a vertical layout to a horizontal layout?

e.g. from this (narrow tall window)

A: -------  
B: -------  
C: --------  
D: --------  

To this (square window)

A:-------- C:-------
B:-------- D:--------

To this (wide window).

A:------ B:------- C:-------- D:---------

As I resize the window? A, B, C, D are edit boxes or comboboxes etc

Obviously, I can use a pagecontrol with 3 (or more) pages and invisible tabs and alternate between these, but I'm hoping to do this without such duplication.

I'm hoping for a solution that does not require me to write code.


Solution

  • This example uses a TFlowPanel. It is added to the form with Align set to alClient. Four TEdit controls are added to the TFlowPanel. When resizing the form they automatically realign themselves in the way you've described.

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    Changing the FlowStyle property allows you to customize the layout behaviour. Above shows the default fsLeftRightTopBottom giving:

     A:-------- B:-------
     C:-------- D:--------
    

    in the square window. Using fsTopBottomLeftRight will give you the layout in the question, however.

     A:-------- C:-------
     B:-------- D:--------