I tried to adjust Tab character width in TLabel, but didn't succeed.
As a prototype I've taken following code:
procedure TForm1.btn1Click(Sender: TObject);
begin
_drawTabbedText('My'#9'sample'#9'text'#9'with'#9'tab'#9'characters', 0, 8);
_drawTabbedText('My'#9'sample'#9'text'#9'with'#9'tab'#9'characters', 15, 7);
_drawTabbedText('My'#9'sample'#9'text'#9'with'#9'tab'#9'characters', 30, 6);
_drawTabbedText('My'#9'sample'#9'text'#9'with'#9'tab'#9'characters', 45, 5);
_drawTabbedText('My'#9'sample'#9'text'#9'with'#9'tab'#9'characters', 60, 4);
_drawTabbedText('My'#9'sample'#9'text'#9'with'#9'tab'#9'characters', 75, 3);
end;
procedure TForm1._drawTabbedText(txt: string; aTop: Integer; TabWidth: DWORD);
var
r: TRect;
begin
r := ClientRect;
r.Top := aTop;
Winapi.Windows.DrawText(Canvas.Handle, LPCWSTR(txt), Length(txt), r, DT_EXPANDTABS or DT_TABSTOP or DT_LEFT or (TabWidth shl 8));
end;
which works.
I converted it into following:
TTabbedLabel = class(TLabel)
protected
procedure DoDrawText(var Rect: TRect; Flags: Longint); override;
end;
procedure TTabbedLabel.DoDrawText(var Rect: TRect; Flags: Integer);
var
TabWidth: DWORD;
begin
TabWidth := 3;
//Flags := DT_TABSTOP or DT_LEFT;
Flags := DWORD(Flags) or DT_TABSTOP or (TabWidth shl 8);
inherited DoDrawText(Rect, Flags);
end;
With this code I didn't achieve tab width adjustment and lost the AutoSize functionality.
How to do it the right way?
Update
With a modified solution from this question: Delphi XE2 VCL styles, remove a style or disable a class skinning from a TLabel tab stop width adjustment works, but AutoSize functionality is still lost.