Delphi: simply highlight text in SynEdit

隐身守侯 提交于 2019-12-22 15:59:07

问题


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!!!!!!


回答1:


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;


来源:https://stackoverflow.com/questions/6721178/delphi-simply-highlight-text-in-synedit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!