我只是注意到,在Delphi XE2中的一些新VCL样式中,试图在Richedit控件中更改文本的颜色不起作用。例如,烟熏夸脱的kamri和碳只能显示黑色文字,而在钴Xemedia中,字体颜色可以更改。这是我用来更改字体颜色的代码(Bold似乎在所有样式中都可以使用)

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

关于如何在使用Delphi XE2样式时如何更改Richedit控件上的字体颜色的任何想法?

有帮助吗?

解决方案

这似乎是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);

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

其他提示

过去的tstymanager.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.
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top