Results 1 to 3 of 3

Thread: Highlighting Language Syntax

  1. #1

    Thread Starter
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    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

  2. #2
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877

    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
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  3. #3

    Thread Starter
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: Highlighting Language Syntax

    Cheers Working Perfectly

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width