delphi xe2のricheditコントロールは、特定のスタイルの下にフォントの色が表示されません

StackOverflow https://stackoverflow.com/questions/9303771

  •  25-10-2019
  •  | 
  •  

質問

Delphi XE2の新しいVCLスタイルのいくつかで、richeditコントロールのテキストの色を変更しようとすることは機能しないことに気付きました。たとえば、Smokey Quarts Kamriと炭素は黒のテキストのみを表示しますが、Cobalt 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

他のヒント

過去のtstylemanager.engine.registerstylehook(trichedit、tricheditstylehookfix); *.dprファイル

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.
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top