Layout manager III |
Top Previous Next |
The third layout manager demo shows how to set different layouts for portrait and landscape display orientation. Let’s say we want to have a form with a big panel and three small panels. In the portrait orientation, small panels should be positioned below the big one and in display orientation they should be positioned right to it.
Let’s start with the design. We need a large panel and small panels.Dimensions don’t matter as they will be set in code.
We have to declare two TLayout fields in the form class. FLayoutLandscape: TLayout;
Both layouts are defined in the InitialzeObject overload, as in the previous examples. Landscape layout contains one Client layout for the Panel1 and one Right layout containing a Top layout containing Panel2, Panel3, and Panel4. The trick here is the Layout.Stretch call which changes Layout.Top behavior. Because of this Stretch, Layout.Top will stretch all contained controls to the same size (plus or minus a pixel – sometimes it is not possible to set all to the same size) so that they will fill the Right container from top to bottom. FLayoutLandscape := Similarly, portrait layout contains a Bottom layout with nested Left layout with the Stretch parameter. Height is specified explicitly and Panel2 to 4 width is set to the same value (plus or minus a pixel) so that they fill up whole row. FLayoutPortrait :=
In the Resize method we have to check Width and Height of the form and apply appropriate layout. procedure TForm1.Resize; |