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

TCustomLabel.AutoSize

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

Declaration

Source position: stdctrls.pp line 1611

public property TCustomLabel.AutoSize : Boolean
  default True;

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.

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.

See also

TCustomLabel.Alignment

  

Horizontal text justification in the control (centered, left- or right-justified).

TCustomLabel.Layout

  

Vertical alignment for control text (at the top, bottom, or center).

TCustomLabel.WordWrap

  

Allows the caption to wrap to multiple lines when it is longer than the available Width.

TCustomLabel.OptimalFill

  

If True, the font size is adjusted for optimal fill of the available space.

TCustomLabel.CalculateSize

  

Gets the height and width needed for the label text.

TCustomLabel.CalculatePreferredSize

  

Calculates the preferred size for the control using its anchoring and constraints.

TControl.Caption

  

The text displayed for the control.

TControl.Anchors

  

The set of anchor definitions for this control.

TControl.AutoSize

  

Allows automatic adjustment of the size for the control, according to its content.

TControl.AdjustSize

  

Smart way to DoAutoSize.


Version 3.2 Generated 2024-02-25 Home