Delphi:只需在SynEdit中突出显示文本 [英] Delphi: simply highlight text in SynEdit

查看:232
本文介绍了Delphi:只需在SynEdit中突出显示文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有20个不同的词。如何在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.

非常感谢!!!!

推荐答案

要突出显示行,您必须使用 OnSpecialLineColors 事件。您可以创建一个函数来查找行中的单词(选中此问题 在Delphi中是否有一个有效的全字搜索功能? ),然后画线

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

检查此代码

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;

这篇关于Delphi:只需在SynEdit中突出显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆