Results 1 to 2 of 2

Thread: [2005] Highlight Keywords

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    22

    [2005] Highlight Keywords

    I've been trying and googling for ages, I've found two solutions to my problem, however both of them don't seem to do a very good job.

    1.

    I have a timer that makes a backup of the RichTextBox in general, so I slotted the following code in the timer and it fires off every 10 seconds,
    Code:
     
    Dim i as Integer = 0
    Do Until i = 25
    
    
                RichTextBoxFR1.Find("'")
                RichTextBoxFR1.SelectionColor = Color.Green
                RichTextBoxFR1.Find("Sub")
                RichTextBoxFR1.SelectionColor = Color.Blue
                i = i + 1
            Loop
    Now I would possibly use this option however it causes bad flickering and highlights everything extremley fast and moves the TextBox around, so it's not very silent ;_;.

    2.
    Realtime Syntax Highlight
    So your probably thinking, well why not use it? It's not quite complex, but it's the fact I'm not sure how intergrate the class into my Current RTB modfication:
    XD Code:
    1. Public Class RichTextBoxFR
    2.     Inherits RichTextBox
    3.  
    4.  
    5.     Public Sub FindAndReplace(ByVal FindText As String, ByVal ReplaceText As String)
    6.         Me.Find(FindText)
    7.         If Not Me.SelectionLength = 0 Then
    8.             Me.SelectedText = ReplaceText
    9.         Else
    10.             MsgBox("The following specified text was not found: " & FindText)
    11.         End If
    12.     End Sub
    13.  
    14.  
    15.     Public Sub FindAndReplace(ByVal FindText As String, ByVal ReplaceText As String, ByVal ReplaceAll As Boolean, _
    16.      ByVal MatchCase As Boolean, ByVal WholeWord As Boolean)
    17.  
    18.         Select Case ReplaceAll
    19.  
    20.             Case False
    21.                 If MatchCase = True Then
    22.                     If WholeWord = True Then
    23.                         Me.Find(FindText, RichTextBoxFinds.MatchCase Or RichTextBoxFinds.WholeWord)
    24.                     Else
    25.                         Me.Find(FindText, RichTextBoxFinds.MatchCase)
    26.                     End If
    27.                 Else
    28.                     If WholeWord = True Then
    29.                         Me.Find(FindText, RichTextBoxFinds.WholeWord)
    30.                     Else
    31.                         Me.Find(FindText)
    32.                     End If
    33.                 End If
    34.  
    35.                 If Not Me.SelectionLength = 0 Then
    36.                     Me.SelectedText = ReplaceText
    37.                 Else
    38.                     MsgBox("The following specified text was not found: " & FindText)
    39.                 End If
    40.  
    41.  
    42.             Case True
    43.  
    44.  
    45.                 Dim i As Integer
    46.                 For i = 0 To Me.TextLength
    47.  
    48.  
    49.                     If MatchCase = True Then
    50.                         If WholeWord = True Then
    51.                             Me.Find(FindText, RichTextBoxFinds.MatchCase Or RichTextBoxFinds.WholeWord)
    52.                         Else
    53.                             Me.Find(FindText, RichTextBoxFinds.MatchCase)
    54.                         End If
    55.                     Else
    56.                         If WholeWord = True Then
    57.                             Me.Find(FindText, RichTextBoxFinds.WholeWord)
    58.                         Else
    59.                             Me.Find(FindText)
    60.                         End If
    61.                     End If
    62.  
    63.  
    64.                     If Not Me.SelectionLength = 0 Then
    65.                         Me.SelectedText = ReplaceText
    66.                     Else
    67.                         MsgBox(i & " occurrence(s) replaced")
    68.                         Exit For
    69.                     End If
    70.                 Next i
    71.  
    72.         End Select
    73.     End Sub
    74.  
    75. End Class
    So in the end, the question is do I just add the subs on or?

  2. #2
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211

    Re: [2005] Highlight Keywords

    You could try somthing like:
    vb Code:
    1. Private Sub HighlightText()
    2.         RichTextBox1.Find("'")
    3.         RichTextBox1.SelectionColor = Color.Green
    4.         RichTextBox1.Find("Sub")
    5.         RichTextBox1.SelectionColor = Color.Blue
    6.     End Sub
    Last edited by Motoxpro; Oct 29th, 2007 at 07:43 AM.

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