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

# TControl.CalculatePreferredSize

Override this method to return the preferred height and width for the control.

## Declaration

Source position: controls.pp line 1377

`protected procedure TControl.CalculatePreferredSize(`
`var PreferredWidth: Integer;`
`var PreferredHeight: Integer;`
`WithThemeSpace: Boolean`
`); virtual;`

## Arguments

`PreferredWidth` |  | Set this argument to the preferred width.
`PreferredHeight` |  | Set this argument to the preferred height.
`WithThemeSpace` |  | True when space around stacked controls should be added.

## Description

Calculates the preferred width and height for a control, which is used by the LCL auto-sizing algorithms as the default size. Negative or zero (0) values are treated as undefined and the LCL uses other sizes instead. This value is independent of constraints and siblings, only the inner parts are relevant.

TWinControl overrides this and asks the interface for theme dependent values. See TWinControl.CalculatePreferredSize for more information.

When WithThemeSpace contains True, space is added for stacking.

For example: TRadioButton has a minimum size. But for stacking multiple TRadioButtons there should be some space around the controls. This space is theme-dependent, so the parameter is passed to the widgetset.