2

我有20个不同的词。如何在 SynEdit 中以不同颜色突出显示这些单词的行?如果无法突出显示行,那么只需突出显示单词。

非常感谢!!!!!!

4

1 回答 1

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;
于 2011-07-17T00:56:49.990 回答