0

I am using the following code to highlight a selection of text in a RichEdit.

procedure TAFormatMain.BtHighLightTextClick(Sender: TObject);
const
  AColor = clYellow;
var
  Format: CHARFORMAT2;
begin
  FillChar(Format, SizeOf(Format), 0);
  with Format do
  begin
    cbSize := SizeOf(Format);
    dwMask := CFM_BACKCOLOR;
    crBackColor := AColor;
    RiEd.Perform(EM_SETCHARFORMAT, SCF_SELECTION, Longint(@Format));
  end;
  RiEd.SelStart := RiEd.SelStart + RiEd.SelLength;
end;

Can anybody tell me how to remove the highlight or what the colour value for "no colour" (equivalent to No Colour in Microsoft Word) would be. I could not find any relevant information about this topic on the net.

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
Rudi
  • 203
  • 2
  • 12

1 Answers1

2

To rest the background color set:

Format.dwEffects := CFE_AUTOBACKCOLOR;
Format.dwMask := CFM_BACKCOLOR; 

See also: CHARFORMAT2 structure

kobik
  • 21,001
  • 4
  • 61
  • 121