When I have this:
if not _nightMode then
TStyleManager.TrySetStyle('Windows', False);
I can owner-draw on Page Control:
procedure TMyMainForm.pcDetailedDrawTab(Control: TCustomTabControl; TabIndex: Integer;
const Rect: TRect; Active: Boolean);
var
can: TCanvas;
cx, by: Integer;
aclr: TColor;
begin
if pcDetailed.Pages[TabIndex] = tsActualData then begin
can := pcDetailed.Canvas;
cx := Rect.Left + Rect.Width div 2;
by := Rect.Bottom - 2;
if _nightMode then aclr := clWhite else aclr := clBlack;
can.Pen.Color := aclr;
can.Brush.Color := aclr;
can.Polygon([Point(cx - 10, by - 10), Point(cx + 10, by - 10), Point(cx, by)]);
end;
end;
When I have this:
if _nightMode then
TStyleManager.TrySetStyle('Cobalt XEMedia', False);
my drawn triangle goes lost.
How to draw a triangle with any VCL style?
Delphi 10 Seattle.
When
Stylesother than the native 'Windows'-style are chosen aStyleHook-class will begin to hook paint relevant windows messages to controls. There are differentStyleHookclasses for different control classes.In case of the
TPageControlit is theTTabControlStyleHook. The hook-class-combination is registered withTCustomStyleEngine.RegisterStyleHook(TCustomTabControl, TTabControlStyleHook);in the class constructor ofTCustomTabControl. This hook class is overriding the controls paint, because it will paint theTCustomTabControlitself when a Style is enabled.What can be done is unregister the default
TStyleHookClassand register one that will let the developer paint:Where
TMyTabControlStyleHookis following:This is however not the exact equivalent to only painting the tabs in the
TPageControl, as theTTabControlStyleHookis responsible for painting the completeTPageControlcontrol.But
TTabControlStyleHookhas theprocedure DrawTab(Canvas: TCanvas; Index: Integer); virtual;which can be overridden for that.Where
DrawTabOverrideis something like thisso it can be called in the
OnDrawTabevent when drawing native and in the StyleHook classDrawTabwhen styled.