简体   繁体   中英

Is the behaviour of the tab character in a Delphi TLabel caption defined?

If I put tab characters into a string and then assign the Caption property of a label from the string what do the tab characters do?

CR characters cause a return, which is useful for displaying a multi-line caption. Tab characters do seem to perform some sort of tabbing action - I'm wondering if this behaviour is defined or predictable. (I guess the behaviour is determined by Windows, not Delphi).

If you put tab characters in a TLabel.Caption , the Caption contains tab characters.

How the tab character is displayed depends on the font you use and Windows itself. A quick test in XE, for instance, on Win7 displays spacing appropriate for tab characters (approximately 8 spaces, in a non-proportional font).

Here's my test. Drop three labels on a form, and add this to the form's OnCreate event:

procedure TForm1.FormCreate(Sender: TObject);
begin
  Label2.Left := Label1.Left;
  Label3.Left := Label2.Left;
  Label1.Caption := 'Some text'#9'Some text'#9'More text';
  Label2.Caption := Label1.Caption;
  Label3.Caption := Label1.Caption;
end;

Here's the output:

样品标签输出

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM