Delphi XE2中的RichEdit控件在某些样式下不会显示字体颜色

发布于 2025-01-05 20:23:51 字数 400 浏览 3 评论 0原文

我刚刚注意到,在 Delphi XE2 中的一些新的 VCL 样式中,尝试更改 RichEdit 控件中的文本颜色不起作用。例如,Smokey Quarts Kamri 和 Carbon 只会以黑色显示文本,而在 Cobalt XEMedia 中,字体颜色可以更改。这是我用来更改字体颜色的代码(粗体似乎适用于所有样式)

 memo.selStart:= length (text);
 memo.selLength:= 0;
 memo.SelAttributes.Color:= clRed;
 memo.SelAttributes.Style:= [fsBold];
 memo.selText := text;

关于如何在使用 Delphi XE2 样式时更改 RichEdit 控件上的字体颜色有什么想法吗?

I just noticed that in some of the new VCL styles in Delphi XE2, trying to change the color of text in a RichEdit control doesn't work. For example Smokey Quarts Kamri and Carbon will only show text in black, while in Cobalt XEMedia the font color can be changed. This is the code I used to change the font color (bold seems to work in all styles)

 memo.selStart:= length (text);
 memo.selLength:= 0;
 memo.SelAttributes.Color:= clRed;
 memo.SelAttributes.Style:= [fsBold];
 memo.selText := text;

Any ideas on how to change the font color on a RichEdit control while using Delphi XE2 styles?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

×眷恋的温暖 2025-01-12 20:23:51

这似乎是一个 VCL 样式错误,但您可以使用样式挂钩轻松修复此问题。

uses
 Vcl.Forms,
 Vcl.Themes,
 Winapi.RichEdit;

type
  TRichEditStyleHookFix = class(TScrollingStyleHook)
  strict private
    procedure EMSetBkgndColor(var Message: TMessage); message EM_SETBKGNDCOLOR;
  end;

{ TRichEditStyleHookFix }

procedure TRichEditStyleHookFix.EMSetBkgndColor(var Message: TMessage);
begin
  Message.LParam := ColorToRGB(StyleServices.GetStyleColor(scEdit));
  Handled := False;
end;

并像这样使用

  TStyleManager.Engine.RegisterStyleHook(TRichEdit, TRichEditStyleHookFix);

在此处输入图像描述
在此处输入图像描述
在此处输入图像描述

It seems a VCL Styles bug, but you can fix this easily using a Style hook.

uses
 Vcl.Forms,
 Vcl.Themes,
 Winapi.RichEdit;

type
  TRichEditStyleHookFix = class(TScrollingStyleHook)
  strict private
    procedure EMSetBkgndColor(var Message: TMessage); message EM_SETBKGNDCOLOR;
  end;

{ TRichEditStyleHookFix }

procedure TRichEditStyleHookFix.EMSetBkgndColor(var Message: TMessage);
begin
  Message.LParam := ColorToRGB(StyleServices.GetStyleColor(scEdit));
  Handled := False;
end;

and use like so

  TStyleManager.Engine.RegisterStyleHook(TRichEdit, TRichEditStyleHookFix);

enter image description here
enter image description here
enter image description here

瑾兮 2025-01-12 20:23:51

过去的
TStyleManager.Engine.RegisterStyleHook(TRichEdit, TRichEditStyleHookFix);
在您的 *.dpr 文件中

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  TStyleManager.TrySetStyle('Carbon');
  TStyleManager.Engine.RegisterStyleHook(TRichEdit, TRichEditStyleHookFix);
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.Run;
end.

Past
TStyleManager.Engine.RegisterStyleHook(TRichEdit, TRichEditStyleHookFix);
in your *.dpr file

eq:

begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  TStyleManager.TrySetStyle('Carbon');
  TStyleManager.Engine.RegisterStyleHook(TRichEdit, TRichEditStyleHookFix);
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.Run;
end.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文