CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2010
    Posts
    17

    Need help with RTB RTF indexing...

    I'm developing a richtextbox that recognises keywords (over 500) and colors them a certain color. This is done by selecting the start index and end index of the word and using this.SelectionColor = Color.Green;

    This works well but performance is poor when the document gets large as it's literally going through each keyword every keypress, selecting the text and changing it. What I need is for the RTF code (\cf1 etc) to be replaced as this will improve performance.

    The problem is how do I convert the index of the keyword from the richtextbox to the RTF file?

    A keyword of 'customer' would be at index 0 on the rtb but not on the rtf as there would be other rtf header text ahead of it. Using rtf.Insert(startIndex, "\\cf2"); would put the color tag in the wrong place.

    I could just search for keywords in the rtf file but this would cause problems firstly by being slower as the rtf will be larger and also it may index keywords that are in headers etc.

    eg. If a keyword was 'new' it may treat the new in the header below as a keyword and insert the cf* tag.

    {
    \rtf1\ansi\ansicpg1252\deff0\deflang1033
    {\fonttbl{\f0\fnil\fcharset0 Courier New;}}
    }


    Any help appreciated.

  2. #2
    Join Date
    Jul 2011
    Posts
    9

    Re: Need help with RTB RTF indexing...

    Hi,

    Its related to performance, but to convert the index of the keyword from the richtextbox to the RTF file, this may help you a little

    Private Sub checkforlinks(ByVal text As String)
    Dim re As New Regex("{\w+}")
    Dim m As Match = re.Match(text)
    While m.Success = True
    rtb.InsertLink(m.ToString, m.Index)
    m = m.NextMatch
    End While
    End Sub

    Tell me if you got any success.
    Refrence- http://icodesnip.com/snippet/csharp/append-formatted-text-to-a-given-position-in-a-rich-text-box-dreamincode
    http://www.vbdotnetforums.com/windows-forms/28809-working-rtf-richtextbox.html#post85318

  3. #3
    Join Date
    Aug 2010
    Posts
    17

    Re: Need help with RTB RTF indexing...

    Hi thanks but I've tried these concepts and they don't work. Seems there's no easy way of converting rtb index to it's rtf index.

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

Featured