When Styles
other than the native 'Windows'-style are chosen a StyleHook
-class will begin to hook paint relevant windows messages to controls. There are different StyleHook
classes for different control classes.
In case of the TPageControl
it is the TTabControlStyleHook
. The hook-class-combination is registered with TCustomStyleEngine.RegisterStyleHook(TCustomTabControl, TTabControlStyleHook);
in the class constructor of TCustomTabControl
. This hook class is overriding the controls paint, because it will paint the TCustomTabControl
itself when a Style is enabled.
What can be done is unregister the default TStyleHookClass
and register one that will let the developer paint:
TCustomStyleEngine.UnRegisterStyleHook(TCustomTabControl, TTabControlStyleHook);
TCustomStyleEngine.RegisterStyleHook(TCustomTabControl, TMyTabControlStyleHook);
Where TMyTabControlStyleHook
is following:
type
TMyTabControlStyleHook = class(TTabControlStyleHook)
public
constructor Create(AControl: TWinControl); override;
end;
constructor TMyTabControlStyleHook.Create(AControl: TWinControl);
begin
inherited Create(AControl);
OverridePaint := False;
end;
This is however not the exact equivalent to only painting the tabs in the TPageControl
, as the TTabControlStyleHook
is responsible for painting the complete TPageControl
control.
But TTabControlStyleHook
has the procedure DrawTab(Canvas: TCanvas; Index: Integer); virtual;
which can be overridden for that.
type
TMyTabControlStyleHook = class(TTabControlStyleHook)
strict protected
procedure DrawTab(Canvas: TCanvas; Index: Integer); override;
end;
procedure TMyTabControlStyleHook.DrawTab(Canvas: TCanvas; Index: Integer);
begin
DrawTabOverride(Canvas, Index, TabRect[Index], TCustomTabControl(Control).MouseInClient);
end;
Where DrawTabOverride
is something like this
procedure DrawTabOverride(Canvas: TCanvas;
TabIndex: Integer; const Rect: TRect; Active: Boolean);
so it can be called in the OnDrawTab
event when drawing native and in the StyleHook class DrawTab
when styled.