【问题标题】:Delphi: simply highlight text in SynEditDelphi:只需在 SynEdit 中突出显示文本
【发布时间】:2011-07-17 00:30:43
【问题描述】:

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

非常感谢!!!!!!

【问题讨论】:

    标签: delphi highlighting synedit


    【解决方案1】:

    要突出显示一行,您必须使用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;
    

    【讨论】:

    • 该事件由Synedit组件调用,每次更改该行的数据。
    猜你喜欢
    • 2019-03-08
    • 2011-09-25
    • 2021-01-15
    • 2013-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-13
    相关资源
    最近更新 更多