Link to home
Start Free TrialLog in
Avatar of ryan_sabarre
ryan_sabarre

asked on

Coloring TPageControl TabSheets

I want to change the color of the TAB whenever that current tab is selected and when you select another tab then the color will be back to normal.
Avatar of ryan_sabarre
ryan_sabarre

ASKER

anybody can help?
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
sorry but your example will not work I'VE USEd the TPageControl with TTabSheet
with delphi 3.0
hum, i used d7
I will received an undeclared identifying:'Canvas'
Hi,

Delphi provides the PageControle with a HotTrack-property, which colors the text of the Tabsheet Blue if the mousepointer is over the tabsheet.

This is implemented in Delphi5. Not sure if it was also provided in version 3.

Maybe this is enough to solve your problem ?
well, don't know if the TPageControl provides a canvas at d3

maybe this change helps

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

hope that helps

meikl ;-)

Sorry, ive used hot track but want to have the whole tab to use different color instead.
TPageControl do not have a canvas property