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

# TWinControl.CalculatePreferredSize

CalculatePreferredSize - calculates the default/preferred width and height for a TWinControl, which is used by the LCL autosizing algorithms as default size

## Declaration

Source position: controls.pp line 1736

`protected procedure TWinControl.CalculatePreferredSize(`
`var PreferredWidth: Integer;`
`var PreferredHeight: Integer;`
`WithThemeSpace: Boolean`
`); override;`

## Description

procedure TWinControl.CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean);

Calls the inherited method to calculate the default/preferred width and height for a TWinControl, which is used by the LCL autosizing algorithms as default size. Only positive values are valid. Negative or 0 are treated as undefined and the LCL uses other sizes instead.

TWinControl overrides this:

- If there are child components, their total preferred size is calculated
- If this value can not be computed (e.g. the children depend too much on their parent clientrect), then the interface is asked for the preferred size

For example the preferred size of a TButton is the size, where the label fits exactly. This depends heavily on the current theme and widgetset.

This value is independent of constraints and siblings, only the inner parts are relevant.

WithThemeSpace: If true, adds space for stacking. For example: TRadioButton has a minimum size. But for stacking multiple TRadioButtons there should be some space around. This space is theme dependent, so it is passed as a parameter to the widgetset.

## See also

TControl.CalculatePreferredSize |  | CalculatePreferredSize - find default/preferred height and width

The latest version of this document can be found at lazarus-ccr.sourceforge.net .