Delphi – Trouble with TPageControl DrawTab

delphiownerdrawntpagecontrol

I set the TPageControl Style to Flat Buttons (tsFlatButtons), and change the tab's button color using the OnDrawTab event.

It works, but the button that is not-active has grey (btnFace color) border!
enter image description here

Any idea how to fix this?

procedure TForm1.PageControlDrawTab(Control: TCustomTabControl;
          TabIndex: Integer; const Rect: TRect; Active: Boolean);

var
  AText: string;
  ARect: TRect;

begin
  with (Control as TPageControl).Canvas do
  begin
    ARect := Rect;
    OffsetRect(ARect, 0, 4);

    Brush.Color := COLOR1;
    FillRect(Rect);

    AText := TPageControl(Control).Pages[TabIndex].Caption;

    with Control.Canvas do   
      DrawText(Control.Canvas.Handle, PChar(AText), -1,ARect, DT_CENTER or DT_SINGLELINE);

  end;
end;

Best Answer

As a workaround, if the design is ok for you enter image description here , you can hide the current tabs:

  for I := 0 to Pred(PageControl1.PageCount) do
    PageControl1.Pages[I].TabVisible := False;

and add a TTabSet with these properties:

BackgroundColor := clGradientActiveCaption;
SelectedColor := clGradientActiveCaption;
Style := tsModernTabs
Related Topic