Delphi 样式编辑器允许在“字体”、“颜色”和“系统颜色”3 个部分中单独更改预定义颜色 启用主题后,我想通过代码以编程方式执行相同的操作。
例如尝试通过代码设置
clHighlight := clRed
不起作用
有办法做到这一点吗?既然样式编辑器可以做到我就充满了希望...但是没有找到线索
我想我可以回答我自己的问题: 我创建了以下助手:
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 项目均为红色!