[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] | Reference for unit 'Controls' (#lcl)

# TChildControlResizeStyle

Defines how child controls are resized / aligned.

## Declaration

Source position: controls.pp line 1938

`type TChildControlResizeStyle = (`
`crsAnchorAligning,` |  | Uses a static layout for normally anchored controls.
`crsScaleChilds,` |  | Scale children keeping fixed space between children.
`crsHomogenousChildResize,` |  | Enlarge children equally, i.e. by the same number of pixels.
`crsHomogenousSpaceResize,` |  | Enlarge space between children equally.
`crsSameSize` |  | Each child gets the same size (maybe one pixel difference).
`);`

## Description

TChildControlResizeStyle is an enumerated type with values that represent the resizing styles used to resize and position child controls in a grid (table) layout.

TChildControlResizeStyle the type used for the EnlargeHorizontal, EnlargeVertical, ShrinkHorizontal, and ShrinkVertical properties in TControlChildSizing.

The enumeration values identify the algorithm used to resize and position the child controls on a parent when its ChildSizing.Layout property set to a value other than clNone. The resizing algorithms apply to child controls which do not have settings in their Align, Anchors, or AnchorSide properties which determine the position / alignment for the child control. Anchored or aligned controls are excluded from the grid layout.

There are different algorithm for sizing the rows and columns in the grid. All algorithms base their calculations on the "PreferredSize" of the child-controls. This is usually the size to which the controls would autosize. For controls that have constraints, the PreferredSize is the size after applying those constraints. (E.g., a TLabel with 20 pixel of text, but a MinSize of 50 will report a PreferredSize of 50).

For each column or row in the grid, all child-controls in that column/row are checked for their PreferredSize. Each columns/rows size is then based on the largest PreferredSize it contains.

Rows/Columns will not shrink below the MinWidth/MinHeight of any child that they contain, even if the algorithm would compute a lower value. Any algorithm will instead shrink other Rows/Columns more aggressively. As a result other row /columns can become invisible due to being zero sized. Also the grid may become wider than the control in which it is shown and will be cut off or need scrolling.

Rows/Columns will shrink (even if being otherwise enlarged) to the smallest MaxWidth/MaxHeight of any child they contain, if - and only if - that child has CellAlignHorizontal/CellAlignVertical = ccaFill. For other alignments rows/ cells will grow based on the PreferredSize. If the PreferredSize is the constrained Maximum, then the cell will still be scaled according to the algorithm, but the child will not fill the entire cell. If rows/columns are constrained by maximum values, then the grid may not fill the entire control in which it is shown.

All algorithms (except crsAnchorAligning) distribute the entire available parent's ClientArea to the grid for the children. Space for each child-controls' BorderSpacing and the parent's ChildSizing's spacing will be put around and between the cells.

See TControl.BorderSpacing and TControl.ChildSizing for more information.

When Constraints.MinWidth/MinHeight is used, the grid can become larger than the ClientArea. And when Constraints.MaxWidth/MaxHeight is used together with ccaFill, then the grid may end up smaller.

Conflicts between MaxWidth and MinWidth are solved by using the MaxWidth.

Child-controls will be sized to their cells dimension if they have BorderSpacing.CellAlignHorizontal/CellAlignVertical = ccaFill. Otherwise they will keep their preferred size and be placed inside the cell according to the specified position in CellAlign.

crsAnchorAligning

  Uses a static layout for the child-controls. Each cell will have exactly the size of the largest PreferredWidth and largest PreferredHeight of any child in its row or column. There is no scaling taking place.

  crsAnchorAligning will not shrink any controls, since each cell will always be big enough to hold the control at its preferred size. crsAnchorAligning may grow a control, if other controls in the same row/column have a bigger preferred size and the control itself has an CellAlign of ccaFill. Cells will not grow past the biggest preferred size of any control in each cells' column or row.

  The derived sizes for child controls and their positions do not change when the parent control is resized. This algorithm does not try to fill unused space on the parent control. Unused space is displayed to right of or beneath the control grid. The grid may also exceed the available space of the parent control.

crsScaleChilds

  Scales child keeps the relative proportion between the children sizes.

  crsScaleChilds scales the size of each column or row to fit the space in the parent, while keeping the ratio of the rows/columns equal to the ratio of the PreferredSizes

  The proportional ratio may not be kept, if child controls are limited by size constraints.

  For a horizontal left-to-right layout with 3 controls A, B, and C:

      Parent.ClientWidth = 120
      A Preferred Width = 10
      B Preferred Width = 20
      C Preferred Width = 30
      A, B, C are scaled by a factor of 2.0 (120/60) for scaled widths of 20, 40 and
      60 respectively.

  If B has a maximum width constraint of 30, then A and C are resized equally with the remaining space made available by the size constraint. Scaling factor for A and C is (120-30)/40 or 2.25.

      Parent.ClientWidth = 120
      A.Width = 23
      B.Width = 30
      C.Width = 67

crsHomogenousChildResize

  Enlarge or shrink child controls equally, i.e. by the same number of pixels.

  crsHomogenousChildResize applies a homogenous size to child controls in the grid layout. All children are grown/shrunk by the same number of pixels.

  The algorithm takes the difference between the parents ClientSize and the sum of all PreferredSizes. This difference (free or missing space in the parent control) is then divided by the number of rows/columns and the correct fraction of the space is added/subtracted to/from the size of each cell.

  For a horizontal left-to-right layout with 3 controls A, B, and C:

      Parent.ClientWidth = 120
      A Preferred Width = 10
      B Preferred Width = 20
      C Preferred Width = 30
      A, B, C are resized to include 20 additional pixels per child control (120-60)/3.
      A.Width = 30
      B.Width = 40
      C.Width = 50

  If B has a maximum width constraint of 30, then the size made available by the constraint is allocated equally to A and C. 120-30-10-30/2=25 pixels.

      A.Width = 35
      B.Width = 30
      C.Width = 55

crsHomogenousSpaceResize

  Enlarges the space between child controls equally.

  crsHomogenousSpaceResize applies a uniform number of pixels as horizontal or vertical spacing between child controls on the same column or row.

  The algorithm takes the difference between the parents ClientSize and the sum of all PreferredSizes. This difference (free or missing space in the parent control) is then divided by the number of rows/columns and the correct fraction of the space is added/subtracted to/from the spacing between the cells and the spacing at the border of the grid.

  For a horizontal left-to-right layout with 3 controls A, B, and C:

      Parent.ClientWidth = 120
      A Preferred Width = 10
      B Preferred Width = 20
      C Preferred Width = 30
      Unused space (120-60)/4=15 is allocated equally as Left, Right, and Horizontal spacing.

  Column widths do not change when the parent control is resized; only the spacing between edges and columns is affected.

crsSameSize

  Each child gets the same size (maybe one pixel difference due to rounding).

  crsSameSize applies a uniform size to all columns or rows in the tabular layout. The unused space on the parent control, after BorderSpacing and ChildSizing spacings are applied, is allocated equally for the number of controls per line in the columns or rows. Size constraints (minimum or maximum) for child controls are enforced if a constraint would be enabled for the derived size. All child controls in the same column or row are given the same derived size.

  For a horizontal left-to-right layout with 3 controls A, B, and C:

      Parent.ClientWidth = 120
      A Preferred Width = 10
      B Preferred Width = 20
      C Preferred Width = 30
      Each column is given a width of 40 pixels (120/3).
      A.Width = 40
      B.Width = 40
      C.Width = 40

  If B has a maximum width constraint of 30, then the space made available by the size constraint is allocated equally to A and C.

      A.Width = 45
      B.Width = 30
      C.Width = 45

  Column widths are recalculated when the parent control is resized.

Please note that the differences between the crsScaleChilds, crsHomogenousChildResize, and crsSameSize algorithms largely disappear when one or more of the child controls have a minimum or maximum size constraint applied.

## See also

TControlChildSizing.EnlargeHorizontal |  | Indicates how child controls are expanded and aligned horizontally on the parent Control.
TControlChildSizing.EnlargeVertical |  | Indicates how child controls are expanded or aligned vertically on the parent Control.
TControlChildSizing.ShrinkHorizontal |  | Indicates how child controls are shrunk and aligned horizontally on the parent Control.
TControlChildSizing.ShrinkVertical |  | Indicates how child controls are shrunk and aligned vertically on the parent Control.
TWinControl.ChildSizing |  | Provides a grid (table) layout for the children of this control.
TWinControl.CalculatePreferredSize |  | Override this method to return a different preferred height and/or width for auto-sizing.
TControl.GetPreferredSize |  | Returns default/preferred height and width, for use in auto-sizing.
TSizeConstraints |  | Holds minimum and maximum values for the width or height of a control.
TControlBorderSpacing |  | Describes the (minimum) spacing around a control.