unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls;
type
TTabsheet = class(ComCtrls.TTabSheet)
private
FColor: TColor;
procedure SetColor(value: TColor);
procedure WMEraseBkGnd(var msg: TWMEraseBkGnd);
message WM_ERASEBKGND;
public
constructor Create(aOwner: TComponent); override;
property Color: TColor read FColor write SetColor;
end;
type
TForm1 = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
procedure FormCreate(Sender: TObject);
procedure PageControl1DrawTab(Control: TCustomTabControl;
TabIndex: Integer; const Rect: TRect; Active: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
constructor TTabsheet.Create(aOwner: TComponent);
begin
inherited;
FColor := clBtnFace;
end;
procedure TTabsheet.SetColor(value: TColor);
begin
if FColor <> value then begin
FColor := value;
Invalidate;
end;
end;
procedure TTabsheet.WMEraseBkGnd(var msg: TWMEraseBkGnd);
begin
if FColor = clBtnFace then
inherited
else begin
Brush.Color := FColor;
Windows.FillRect(msg.dc, Clientrect, Brush.handle);
msg.result := 1;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Tabsheet1.color := clWhite;
TabSheet2.color := clLime
end;
// PageControl1.OwnerDraw := true !
procedure TForm1.PageControl1DrawTab(Control: TCustomTabControl;
TabIndex: Integer; const Rect: TRect; Active: Boolean);
var
AText: string;
APoint: TPoint;
begin
with (Control as TPageControl).Canvas do
begin
Brush.Color := clred;
FillRect(Rect);
AText := TPageControl(Control).Pages[TabIndex].Caption;
with Control.Canvas do
begin
APoint.x := (Rect.Right - Rect.Left) div 2 - TextWidth(AText) div 2;
APoint.y := (Rect.Bottom - Rect.Top) div 2 - TextHeight(AText) div 2;
TextRect(Rect, Rect.Left + APoint.x, Rect.Top + APoint.y, AText);
end;
end
end;
end.