Delphi tTabcontrol question

298 views
Skip to first unread message

Gavin Nesmith

unread,
Apr 1, 2014, 3:48:23 AM4/1/14
to hard...@googlegroups.com
Dose anyone know how to color the tabs on a tabcontrol in Delphi 2006. I want each tab to be a different color. 

Thank you,

Gavin

Faisal

unread,
Apr 1, 2014, 6:07:11 AM4/1/14
to hard...@googlegroups.com
Hi Gavin,
              You need to write the OnDrawTab event for this and use control canvas to change the color and font. Here is the sample code works well for me. Also you need to set the property ownerDraw = true and also changing the tabPosition = tpTop will make good effect.

procedure TfrmFrame.tabPageDrawTab(Control: TCustomTabControl;
  TabIndex: Integer; const Rect: TRect; Active: Boolean);
var
  tabName : String;
  TmpRect : TRect;
begin
  inherited;
  with (Control as TTabControl).Canvas do
    begin
      tabName := String(TTabControl(Control).Tabs[TabIndex]);
      if tabName = 'Notes' then
      begin
        Font.Color := clRed;
        brush.Color := clYellow;
        Fillrect(Rect);
      end;
      TmpRect   :=   Rect;
      OffsetRect(TmpRect,   0,   4);
      DrawText(Handle,   PChar(tabName),   -1,   TmpRect,   DT_TOP);
    end;
end;

Regards,
Faisal

Kevin Toppenberg

unread,
Apr 1, 2014, 7:51:28 AM4/1/14
to hard...@googlegroups.com
You might have to draw the text also. 

Kevin
Reply all
Reply to author
Forward
0 new messages