Good Day!
I need to change text color of caption of some TabSheet in TPageControl. Something like this on picture
I know how it can be done using OnDrawTab. But if i enabled OwnerDraw, decoration of Windows XP Theme disappears. That's why i try to draw this decoration manually. This is how i tried to do this:
procedure TForm1.PageControl1DrawTab(Control: TCustomTabControl;
TabIndex: Integer; const Rect: TRect; Active: Boolean);
var
FRect: TRect;
Text: string;
begin
FRect := Control.TabRect(TabIndex);
if Active then
ThemeServices.DrawElement(Control.Canvas.Handle, ThemeServices.GetElementDetails(ttTabItemHot), FRect)
else
ThemeServices.DrawElement(Control.Canvas.Handle, ThemeServices.GetElementDetails(ttTabItemNormal), FRect);
Text := PageControl1.Pages[TabIndex].Caption;
Control.Canvas.Brush.Style := bsClear;
if not Active then
FRect.Top := FRect.Top + 4;
DrawText(Control.Canvas.Handle, PChar(Text), Length(Text), FRect, DT_SINGLELINE or DT_CENTER or DT_VCENTER);
end;
And i got this
(left - OwnerDraw version, right - default draw)
As you can see, TabSheets have some borders that's are not overdrawn. And I can't overdraw this borders.
How can i draw background of tab correctly (like PageControl on the right)?
A possible solution is override the
PaintWindow
method of theTPageControl
instead of use the ownerdraw , in this way you can control every visual aspect of the tabs.Check this basic sample.
And this is the result.