With Delphi 12 how to change style defaut and system colors programmatically?

89 Views Asked by At

Delphi Style editor allows to change individualy the predefined colors in 3 sections "Fonts" "Colors" and "SysColors" With themes enabled, I would like to do the same but programmatically by code.

For example trying to set by code

clHighlight := clRed

doesn't work

Is there a way to do this ? Since the style editor can do it I was full of hope ... but did not find a clue

1

There are 1 best solutions below

0
On

I guess I'm allowed to answer my own question : I have created the following helper :

unit StyleColor;

interface

uses Vcl.Themes, Vcl.Styles, Vcl.StyleAPI;

   TStyleHelper = class helper for TCustomStyle
   public
      procedure DoSetSystemColor(SysColor: TColor; Color: TColor);
   end;

implementation

{ TStyleHelper }

procedure TStyleHelper.DoSetSystemColor(SysColor: TColor; Color: TColor);
begin
   TseStyle(FSource).SysColors[SysColor] := Color;
end;

end.



and when I call it like this : (with themes enabled)

if TStyleManager.ActiveStyle is TCustomStyle then
begin
   TCustomStyle(TStyleManager.ActiveStyle).DoSetSystemColor(clHighLight, clRed);
end;

it Works !!!! all clHighLight items are Colored in Red !