...change the Background Color in TRichEdit for the selected characters?

Author: Thomas Stutz

Category: VCL

uses
  
RichEdit;

procedure RE_SetSelBgColor(RichEdit: TRichEdit; AColor: TColor);
var
  
Format: CHARFORMAT2;
begin
  
FillChar(Format, SizeOf(Format), 0);
  with Format do
  begin
    
cbSize := SizeOf(Format);
    dwMask := CFM_BACKCOLOR;
    crBackColor := AColor;
    Richedit.Perform(EM_SETCHARFORMAT, SCF_SELECTION, Longint(@Format));
  end;
end;

// Example: Set clYellow background color for the selected text.
procedure TForm1.Button1Click(Sender: TObject);
begin
  
RE_SetSelBgColor(RichEdit1, clYellow);
end;

 

printed from
www.swissdelphicenter.ch
developers knowledge base