1.) 设置 TPageControl 属性:
TabPosition := tpLeft;
OwnerDraw := True;
TabWidth := 180; //set to any adequate value because
// TPageControl doesn't have a measure event handler
2.) 使用以下 OnDrawTab 代码:
procedure TForm1.PageControl1DrawTab(Control: TCustomTabControl;
TabIndex: Integer; const Rect: TRect; Active: Boolean);
var
I: Integer;
PageControl: TPageControl;
TextFormat: TTextFormat;
Text: string;
TextRect: TRect;
begin
PageControl := Control as TPageControl;
Text := PageControl.Pages[TabIndex].Caption;
for I := Length(Text) - 1 downto 1 do
begin
Text := Copy(Text, 1, I) + sLineBreak + Copy(Text, I+1, MaxInt);
end;
TextRect := Rect;
TextRect.Left := TextRect.Left + 5;
TextRect.Top := TextRect.Top + 3;
TextFormat := [tfCenter];
PageControl.Canvas.TextRect(
TextRect,
Text,
TextFormat
);
end;
3.) 编译、开始和享受!