Custom text color for Page control tabs

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #34196
    JM-DG
    Participant

    Hi!

    Registered user using Windows 7 64bits, latest alpha controls component 7.25.

    I managed to draw custom text with different colors per tabs on a standard Pagecontrol component.

    When I use a standard “unskinned” PageControl there isn't any problem.

    However when skinning it the text turns back to black.

    So I wonder how can we make custom colored text tabs skinned?

    Here's the “drawing” code for anybody willing to help.

    Code:
    procedure TForm1.PageControlDrawTab(Control: TCustomTabControl;
    TabIndex: Integer; const Rect: TRect; Active: Boolean);
    var
    y : Integer;
    x : Integer;
    aRect: TRect;
    begin
    Control.Canvas.Font.Color := clWindowText;
    if TabIndex = 0 then
    Control.Canvas.Font.Color := clRed;
    if TabIndex = 1 then
    Control.Canvas.Font.Color := clBlue;
    if TabIndex = 2 then
    Control.Canvas.Font.Color := clBlack;
    if TabIndex = 3 then
    Control.Canvas.Font.Color := clGreen;
    if TabIndex = 4 then
    Control.Canvas.Font.Color := clFuchsia;

    if Active then
    begin
    //Fill the tab rect
    Control.Canvas.Brush.Color := clBtnFace;
    Control.Canvas.FillRect(Rect);
    //Fill the background
    aRect.Left:=1;
    aRect.Right:=Control.Width-1;
    aRect.Bottom:=Control.Height-1;
    aRect.Top:=Rect.Bottom+1;
    Control.Canvas.FillRect(aRect);
    end
    else
    begin
    //Fill the tab rect
    Control.Canvas.Brush.Color := clBtnFace;
    Control.Canvas.FillRect(Rect);
    end;

    y := Rect.Top + ((Rect.Bottom – Rect.Top – Control.Canvas.TextHeight(TTabControl(Control).Tabs[TabIndex])) div 2) + 1;
    x := Rect.Left + ((Rect.Right – Rect.Left – Control.Canvas.TextWidth (TTabControl(Control).Tabs[TabIndex])) div 2);
    //draw the tab title
    Control.Canvas.TextOut(x,y,TTabControl(Control).Tabs[TabIndex]);
    end;

    Thanks!

    ______

    JM-DG

    #44225
    Support
    Keymaster

    Hello

    I'll try your code soon. You can check this demo also, maybe you will found something useful there.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.