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

# TToolButton.CalculatePreferredSize

Calculates the preferred dimensions for new instances of the control.

## Declaration

Source position: comctrls.pp line 2167

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

## Arguments

`PreferredWidth` |  | Returns the preferred width for a new instance of the tool button class.
`PreferredHeight` |  | Returns the preferred height for a new instance of the tool button class.
`WithThemeSpace` |  | Not used in the current implementation.

## Description

CalculatePreferredSize is an overridden method in TToolButton. It returns the calculated width and height for the control in the PreferredWidth and PreferredHeight variable arguments. It re-implements the method introduced in TControl to return non-empty values in the arguments.

No actions are performed in the method if a TToolBar instance has not been assigned as the Parent for the control. In this case, the values in the PreferredWidth and PreferredHeight arguments are not changed from their values on entry.

WithThemeSpace indicates whether additional space is reserved for theme element details. It is not used in the current implementation of the method.

CalculatePreferredSize calculates the size needed to represent the icon and text on the control. The value in Style determines whether the icon and/or text values are needed in the calculated values. When both are needed, additional space is reserved between the icon and text as indicated in the cHorIconTextDist or cVerIconTextDist constants. The number of pixels is scaled to the PPI setting for the control Font and applied to the calculated values.

CalculatePreferredSize includes space (when needed) for a frame around the control, a drop-down indicator, or the height / width for a divider or separator button. The Style property determines which values are required.

CalculatePreferredSize is called form the GetPreferredSize method when it has not already been called for the class instance.

## See also

TToolButton.Style |  | Determines the display style for the tool button.
TToolButton.GetPreferredSize |  | Returns default/preferred height and width, for use in auto-sizing.
TToolBar |  | Implements an application tool bar with buttons or other visual controls.
TControl.CalculatePreferredSize |  | Override this method to return the preferred height and width for the control.