Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8651599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:06:40+00:00 2026-06-12T14:06:40+00:00

I have a TabControl in which each tab represents a distinct set of data.

  • 0

I have a TabControl in which each tab represents a distinct set of data. My application uses VCL Styles, and thus setting OwnerDraw to True does not lead to OnDrawTab being called. I was wondering if it is possible to somehow intercept the routine which draws a specific control using VCL Styles (in my case, TabControl), and change the way the control is drawn (for instance, change the Canvas.Font, etc.).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:06:41+00:00Added an answer on June 12, 2026 at 2:06 pm

    To change the font color of a tabsheet using the vcl styles, you must override the DrawTab method of the Vcl.ComCtrls.TTabControlStyleHook style hook and use your own code to draw the tab and set the color font.

    Try this sample

    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls;
    
    type
      TForm1 = class(TForm)
        PageControl1: TPageControl;
        TabSheet1: TTabSheet;
        TabSheet2: TTabSheet;
        TabSheet3: TTabSheet;
        TabSheet4: TTabSheet;
        TabSheet5: TTabSheet;
        TabSheet6: TTabSheet;
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    uses
      Vcl.Styles,
      Vcl.Themes;
    
    {$R *.dfm}
    
    type
      TTabFontColorStyleHook= class(Vcl.ComCtrls.TTabControlStyleHook)
      protected
        procedure DrawTab(Canvas: TCanvas; Index: Integer); override;
      end;
    
      TWinControlClass = class(TWinControl);
      TCustomTabControlClass = class(TCustomTabControl);
    
    
    procedure TTabFontColorStyleHook.DrawTab(Canvas: TCanvas; Index: Integer);
    var
      LDetails    : TThemedElementDetails;
      LImageIndex : Integer;
      LThemedTab  : TThemedTab;
      LIconRect   : TRect;
      R, LayoutR  : TRect;
      LImageW, LImageH, DxImage : Integer;
      LTextX, LTextY: Integer;
      LTextColor    : TColor;
    
        procedure DrawControlText(const S: string; var R: TRect; Flags: Cardinal);
        var
          TextFormat: TTextFormatFlags;
        begin
          Canvas.Font       := TWinControlClass(Control).Font;
          TextFormat        := TTextFormatFlags(Flags);
          Canvas.Font.Color := LTextColor;
          StyleServices.DrawText(Canvas.Handle, LDetails, S, R, TextFormat, Canvas.Font.Color);
        end;
    
        procedure AngleTextOut2(Canvas: TCanvas; Angle, X,
          Y: Integer; const Text: string);
        var
          LSavedDC: Integer;
        begin
          LSavedDC := SaveDC(Canvas.Handle);
          try
            SetBkMode(Canvas.Handle, TRANSPARENT);
            Canvas.Font.Orientation := Angle;
            Canvas.TextOut(X, Y, Text);
          finally
            RestoreDC(Canvas.Handle, LSavedDC);
          end;
        end;
    
    begin
      if (Images <> nil) and (Index < Images.Count) then
      begin
        LImageW := Images.Width;
        LImageH := Images.Height;
        DxImage := 3;
      end
      else
      begin
        LImageW := 0;
        LImageH := 0;
        DxImage := 0;
      end;
    
      R := TabRect[Index];
      if R.Left < 0 then Exit;
    
      if TabPosition in [tpTop, tpBottom] then
      begin
        if Index = TabIndex then
          InflateRect(R, 0, 2);
      end
      else if Index = TabIndex then
        Dec(R.Left, 2) else Dec(R.Right, 2);
    
      Canvas.Font.Assign(TCustomTabControlClass(Control).Font);
      LayoutR := R;
      LThemedTab := ttTabDontCare;
      //Get the type of the active tab
      case TabPosition of
        tpTop:
          begin
            if Index = TabIndex then
              LThemedTab := ttTabItemSelected
            else if (Index = HotTabIndex) and MouseInControl then
              LThemedTab := ttTabItemHot
            else
              LThemedTab := ttTabItemNormal;
          end;
        tpLeft:
          begin
            if Index = TabIndex then
              LThemedTab := ttTabItemLeftEdgeSelected
            else if (Index = HotTabIndex) and MouseInControl then
              LThemedTab := ttTabItemLeftEdgeHot
            else
              LThemedTab := ttTabItemLeftEdgeNormal;
          end;
        tpBottom:
          begin
            if Index = TabIndex then
              LThemedTab := ttTabItemBothEdgeSelected
            else if (Index = HotTabIndex) and MouseInControl then
              LThemedTab := ttTabItemBothEdgeHot
            else
              LThemedTab := ttTabItemBothEdgeNormal;
          end;
        tpRight:
          begin
            if Index = TabIndex then
              LThemedTab := ttTabItemRightEdgeSelected
            else if (Index = HotTabIndex) and MouseInControl then
              LThemedTab := ttTabItemRightEdgeHot
            else
              LThemedTab := ttTabItemRightEdgeNormal;
          end;
      end;
    
      //draw the tab
      if StyleServices.Available then
      begin
        LDetails := StyleServices.GetElementDetails(LThemedTab);//necesary for  DrawControlText
        StyleServices.DrawElement(Canvas.Handle, LDetails, R);
      end;
    
      //get the index of the image (icon)
      if Control is TCustomTabControl then
        LImageIndex := TCustomTabControlClass(Control).GetImageIndex(Index)
      else
        LImageIndex := Index;
    
      //draw the image
      if (Images <> nil) and (LImageIndex >= 0) and (LImageIndex < Images.Count) then
      begin
        LIconRect := LayoutR;
        case TabPosition of
          tpTop, tpBottom:
            begin
              LIconRect.Left := LIconRect.Left + DxImage;
              LIconRect.Right := LIconRect.Left + LImageW;
              LayoutR.Left := LIconRect.Right;
              LIconRect.Top := LIconRect.Top + (LIconRect.Bottom - LIconRect.Top) div 2 - LImageH div 2;
              if (TabPosition = tpTop) and (Index = TabIndex) then
                OffsetRect(LIconRect, 0, -1)
              else
              if (TabPosition = tpBottom) and (Index = TabIndex) then
                OffsetRect(LIconRect, 0, 1);
            end;
          tpLeft:
            begin
              LIconRect.Bottom := LIconRect.Bottom - DxImage;
              LIconRect.Top := LIconRect.Bottom - LImageH;
              LayoutR.Bottom := LIconRect.Top;
              LIconRect.Left := LIconRect.Left + (LIconRect.Right - LIconRect.Left) div 2 - LImageW div 2;
            end;
          tpRight:
            begin
              LIconRect.Top := LIconRect.Top + DxImage;
              LIconRect.Bottom := LIconRect.Top + LImageH;
              LayoutR.Top := LIconRect.Bottom;
              LIconRect.Left := LIconRect.Left + (LIconRect.Right - LIconRect.Left) div 2 - LImageW div 2;
            end;
        end;
        if StyleServices.Available then
          StyleServices.DrawIcon(Canvas.Handle, LDetails, LIconRect, Images.Handle, LImageIndex);
      end;
    
      //draw the text of the tab
      if StyleServices.Available then
      begin
    
        //here you set the color of the font
        LTextColor:=clRed;
    
        if (TabPosition = tpTop) and (Index = TabIndex) then
          OffsetRect(LayoutR, 0, -1)
        else
        if (TabPosition = tpBottom) and (Index = TabIndex) then
          OffsetRect(LayoutR, 0, 1);
    
        if TabPosition = tpLeft then
        begin
          LTextX := LayoutR.Left + (LayoutR.Right - LayoutR.Left) div 2 - Canvas.TextHeight(Tabs[Index]) div 2;
          LTextY := LayoutR.Top + (LayoutR.Bottom - LayoutR.Top) div 2 + Canvas.TextWidth(Tabs[Index]) div 2;
          Canvas.Font.Color := LTextColor;
          AngleTextOut2(Canvas, 900, LTextX, LTextY, Tabs[Index]);
        end
        else
        if TabPosition = tpRight then
        begin
          LTextX := LayoutR.Left + (LayoutR.Right - LayoutR.Left) div 2 + Canvas.TextHeight(Tabs[Index]) div 2;
          LTextY := LayoutR.Top + (LayoutR.Bottom - LayoutR.Top) div 2 - Canvas.TextWidth(Tabs[Index]) div 2;
          Canvas.Font.Color := LTextColor;
          AngleTextOut2(Canvas, -900, LTextX, LTextY, Tabs[Index]);
        end
        else
         DrawControlText(Tabs[Index], LayoutR, DT_VCENTER or DT_CENTER or DT_SINGLELINE  or DT_NOCLIP);
      end;
    end;
    
    
    
    initialization
      TStyleManager.Engine.RegisterStyleHook(TCustomTabControl, TTabFontColorStyleHook);
      TStyleManager.Engine.RegisterStyleHook(TTabControl, TTabFontColorStyleHook);
    end.
    

    And this is the result

    enter image description here

    Also exist several resources which can help you when you need customize a tabsheet and pagecontrol components using vcl styles.

    • Creating colorful tabsheets with the VCL Styles
    • Added border to TTabColorControlStyleHook
    • Check the code of the Vcl.Styles.ColorTabs unit, which is part of the vcl styles utils project.
    • How can i change text color of themed TabSheet caption?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a forms application which uses a TabControl. For each tab I
I have a large XAML project which will have a main TabControl and each
i have a form, which hosts a tabcontrol. each of these tabs have plenty
I have a Silverlight Usercontrol where I have a tabcontrol which uses a couple
I have a TabControl and each Tab can contain the same UI but with
I have close button in the header of each tab of TabControl. Tabs are
I have an application which has a tabcontrol that contains two tabpages. I have
I am experiencing a very weird problem: In WPF I have a tabControl which
I have a WPF TabControl which displays UserControl s. Some UserControl s are larger
I have a TabControl in my XAML which is just an empty control as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.