使用 Delphi 12 如何以编程方式更改默认样式和系统颜色?

问题描述 投票:0回答:1

Delphi 样式编辑器允许在“字体”、“颜色”和“系统颜色”3 个部分中单独更改预定义颜色 启用主题后,我想通过代码以编程方式执行相同的操作。

例如尝试通过代码设置

clHighlight := clRed

不起作用

有办法做到这一点吗?既然样式编辑器可以做到我就充满了希望...但是没有找到线索

delphi themes vcl-styles vcl-styles.-utils
1个回答
0
投票

我想我可以回答我自己的问题: 我创建了以下助手:

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;

它有效!所有 clHighLight 项目均为红色!

© www.soinside.com 2019 - 2024. All rights reserved.