delphihighlightingsynedit

Delphi: simply highlight text in SynEdit


I have 20 different words. How to highlight rows with those words in different colors in SynEdit? If it is not possible to highlight rows then just to highlight the words.

Big Thanks!!!!!!


Solution

  • To highlight a row you must use the OnSpecialLineColors Event. You can create a function to find the word in the line (check this question Is There An Efficient Whole Word Search Function in Delphi?) and then paint the line

    Check this code

    procedure TFrmMain.SynEditCodeSpecialLineColors(Sender: TObject;
      Line: integer; var Special: boolean; var FG, BG: TColor);
    begin
      If LineContainsWord(Line) then //here check if the word is in the line
      begin
       FG      := clYellow; //Text Color
       BG      := clBlue; //BackGround
       Special := True; //Must be true
      end;        
    end;