RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCustomLabel.AutoSize Property

Determines whether the size of the label automatically resizes to accommodate the text.

Pascal
property AutoSize: Boolean;
C++
__property Boolean AutoSize;

Use AutoSize to make the label adjust its size automatically so the client area accommodates the height and width of the text. When AutoSize is false, the label is fixed in size. When AutoSize is true, the size of the label readjusts whenever the text changes. The size of the label is also readjusts when the Font property changes. 

When WordWrap is true, the width of the label is fixed. If AutoSize is also true, changes to the text cause the label to change in height. When AutoSize is true and WordWrap is false, the font determines the height of the label, and changes to the text cause the label to change in width.  

C++ Examples: 

 

/*
The following code keeps the size of the label control 
constant, even though the length of the label’s caption 
changes. As a result, the caption of the label is probably 
too long to display in the label when the user clicks the 
button:
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Label1->AutoSize = false;
  Label1->Caption = "This string is too long as the caption of this label";
}

 

Delphi Examples: 

{
The following code keeps the size of the label control 
constant, even though the length of the label’s caption 
changes. As a result, the caption of the label is probably 
too long to display in the label when the user clicks the 
button:
} 
procedure TForm1.Button1Click(Sender: TObject);
begin
  Label1.AutoSize := False;
  Label1.Caption := 
    'This string is too long as the caption of this label';
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!