Highlighting Language Syntax
Hey does anyone know of a effiecient method of highlighting a richtext box for keywords. When I open the file and format the colors this is the code that i use for the keywords
Code:
foreach(string word in this.ReservedWords)
{
Regex rgx=new Regex(word , RegexOptions.IgnoreCase);
MatchCollection mCol=rgx.Matches(this.rtfSource.Text);
foreach(Match m in mCol)
{
this.rtfSource.HideSelection=true;
this.rtfSource.Select(m.Index , m.Length);
this.rtfSource.SelectionColor=Color.Blue;
this.rtfSource.SelectionStart=m.Index + m.Length;
this.rtfSource.SelectionLength=0;
}
}
This takes a long time to format, does anyone have any sugestions of a better way?
Thanks
Re: Highlighting Language Syntax
I had a go at it recntly in VB and C#. After trying a while with different algorithms i came to the conclusion that no matter how fast is your algoritm it wont be able to cope if you have large amount of text. So I did some searching and found that the best approach is to color only visble lines not "ALL" lines. If you notice MS FrontPage ueses the same technique. Here is a very good example in VB.Net(can convert it to C#), there are more on CodePrject. Hope it helps.
http://www.codeproject.com/vb/net/re...axcoloring.asp
Re: Highlighting Language Syntax
Cheers Working Perfectly :)
Thanks