Link to home
Start Free TrialLog in
Avatar of juank
juank

asked on

TTabSheets - May I Change the tab color?

Hi folks:

Here a goes a couple of little questions related with TTabSheets.

How could I do in D3 to:

1) Assign a color to the Tab of a TTabSheet
2) Make that color change if the TabSheet is active or not

Thank you and regards

JuanK
Avatar of Ferruccio Accalai
Ferruccio Accalai
Flag of Italy image

set PageControl.OwnerDraw to true then

in DrawTab this

procedure TForm1.PageControl1DrawTab(Control: TCustomTabControl;
  TabIndex: Integer; const Rect: TRect; Active: Boolean);
begin
with control.Canvas do begin
      if active then begin
      Font.Style := [fsBold];
    brush.Color := clblue;
      end else begin
    font.Style := [];
    brush.Color := clred;
    end;
      TextOut(Rect.Left + Font.Size,
                  Rect.Top + 2,PageControl1.Pages[tabindex].Caption);
      end;

end;
well, my version,
sorry to say, f68, your painting routine paints a bit ugly,
and will left a small blue line on the canvas

//property OwnerDraw must be set to true
procedure TForm1.PageControl1DrawTab(Control: TCustomTabControl;
  TabIndex: Integer; const Rect: TRect; Active: Boolean);
var ARect : TRect;
begin
  ARect := Rect;
  //clear complete
  control.Canvas.brush.Color := clBtnFace;
  control.Canvas.FillRect(ARect);
  InflateRect(ARect,-2,-2);
  //decide the color
  if active then
    control.Canvas.brush.Color := clRed
  else
    control.Canvas.brush.Color := clBtnFace;
  //paint the tab
  control.Canvas.FillRect(ARect);
  Control.Canvas.TextOut(ARect.Left+2,ARect.top+2,
                         TPageControl(Control).Pages[TabIndex].Caption);
end;

meikl ;-)
well, this problem happens to me too,
if i change also the fontstyle as f68 ([fsBold],[])

instead of
  Control.Canvas.TextOut(ARect.Left+2,ARect.top+2,
                         TPageControl(Control).Pages[TabIndex].Caption);
use
  control.Canvas.TextRect(ARect,ARect.Left+2,ARect.top+1,
                         TPageControl(Control).Pages[TabIndex].Caption);

meikl ;-)
--> if i change also the fontstyle as f68 ([fsBold],[])
glad about it :)))) BTW in fact your method should be better...
F68 ;-)
Avatar of juank
juank

ASKER

Hi folks.

Thank you for your answers, but where do I find the property OwnerDraw?? And the DrawTab Event ??

Let me remember you all that this question is related with Delphi 3, and I couldn't find them, even in the help :-(

Best regards,

Juank
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of juank

ASKER

Ok.

Anyway, don't worry as I convinced the client that the colored tabs were "annoying"
Rgds.

Juank