Delphi:简单地突出显示SynEdit中的文本

max*_*fax 2 delphi highlighting synedit

我有20个不同的词.如何在SynEdit中突出显示具有不同颜色的单词的行?如果无法突出显示行,则只需突出显示单词.

十分感谢!!!!!!

RRU*_*RUZ 7

要突出显示一行,您必须使用OnSpecialLineColors事件.您可以创建一个函数来查找行中的单词(检查此问题Is There An Efficient Whole Word Search Function in Delphi?),然后绘制该行

检查此代码

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;
Run Code Online (Sandbox Code Playgroud)

  • 每次更改行的数据时,Synedit组件都会调用该事件. (3认同)