Sign in Join
FPDoc Onlineexperiment

TLabel.AutoSize property

Member of TLabelpublishedIn unit StdCtrls

Enables or disables auto-sizing the control to its content.

Declaration

pascal
property AutoSize:;

Description

AutoSize is a Boolean property reintroduced in TCustomLabel to set its default value to True.

Auto-sizing behavior in TCustomLabel differs from the implementation in the ancestor class (TControl). For example, a label can become bigger or smaller to accommodate a longer or shorter caption. In other controls, the property may control only the height for the control based on the Font size.

AutoSize causes the control to be resized to fit the content in the Caption property. This can include changing the values in Top, Left, Width, or Height if the corresponding edge(s) are not fixed using the Anchors property. Any edge included in Anchors is not altered when the control is auto-sized.

In addition to Anchors, auto-sizing behavior is also influenced by the Alignment and WordWrap properties for the control. When Alignment is set to taLeftJust or taRightJustify, and AutoSize is not enabled, the control displays the caption value aligned to the edge specified in Alignment. Excess characters which do not fit in the Width for the control are truncated.

When AutoSize is enabled, the control is resized to fit the characters in Caption by repositioning the opposite edge for the Alignment value. For taLeftJustify, the right edge is expanded or contracted by changing the value in Width. For taRightJustify, the value in Left is repositioned until all characters are displayed using the Alignment.

Use the Anchors property to fix the position for an edge during auto-sizing regardless of the value in the Alignment property. For example, when Anchors is set to [akTop, akLeft, akRight], only the height for the control can be altered when AutoSize is enabled.

When WordWrap is enabled, and both the left and right edges are included in Anchors, the height for the label control is adjusted during auto-sizing.

WordWrapLength is another parameter to control the text width when WordWrap is active. It is primarily useful when the label text is rotated (by setting the label's Font.Orientation to the 10-fold rotation angle in degrees). In case of rotated text, again the width and height of the autosized label are adjusted to tightly enclose the text.

Simultaneous use of both AutoSize and OptimalFill can have conflicting results. AutoSize tries to use the existing Font to determine the control width /height. OptimalFill adjusts the Font size to fill the control width/height.

Changing the value for the property causes AdjustSize (in TControl) to be called when the property is enabled.

This description is the one of StdCtrls.TCustomLabel.AutoSize.

See also

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.