Link to home
Start Free TrialLog in
Avatar of mattlaver
mattlaver

asked on

Tabcontrol colour problem

This is probably really easy, however driving me mad!

How do I set the color property of the individual tabcontrol tabs?, I am creating a variable amount of tabs at run time with the TTabcontrol component.

I would really like to stick to the native VCL components in Delphi 5 to keep things simple.

Thanks!

Matt
Avatar of nnbbb09
nnbbb09


Matt,

I think the only way to change the colour of the tabs is to use the OnDrawTab event handler.
This is some code that I posted for a previous answer :

procedure TForm1.PageControl1DrawTab(Control: TCustomTabControl;
TabIndex: Integer; const Rect: TRect; Active: Boolean);
var
tmpRect:TRect;
begin
With Control as TPageControl do
begin
  if Active then
    Canvas.Brush.Color:=clAqua
  else
    Canvas.Brush.Color:=clBtnFace;

  Canvas.FillRect(Rect);
  tmpRect:=Rect;
  DrawText(Canvas.Handle,
           pChar(Pages[TabIndex].Caption),
           -1,
           tmpRect,
           DT_CENTER or
           DT_SINGLELINE or
           DT_VCENTER);
end;
end;

All this does is paint the active tab aqua. But you could amend it to paint various tabs. Remember to set ownerdraw to true for the pagecontrol

Jo
nnbbb09:

I tried your code in D6, and there was a problem with the
DrawText function.  As the pagecontrol was first initiated, all tab captions would display the same text as the set active tab.  When one tab was clicked, its caption and the previous tab caption would display the same text as the currently selective one.  Any idea how to fix this problem?
ASKER CERTIFIED SOLUTION
Avatar of SpideyMod
SpideyMod

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