Click here to Skip to main content
15,910,603 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
the error is coming from highlight sub for richtextbox:


VB
        Highlight(Color.FromArgb(57, 135, 214), 0, "MOTOR")
        Highlight(Color.FromArgb(57, 135, 214), 0, "SCALLING")
        Highlight(Color.FromArgb(57, 135, 214), 0, "VALVE")
        Highlight(Color.Green, 0, "inputVariable")
        Highlight(Color.DarkOrange, 0, "outputVariable")
        Highlight(Color.Red, 0, "<descriptionFFB execAfter=")
        Highlight(Color.DarkRed, 1, "<FBDExchangeFile>")
        Highlight(Color.DarkRed, 1, "</FBDExchangeFile>")
        Highlight(Color.DarkRed, 1, "</FFBBlock>")
        Highlight(Color.DarkRed, 1, "<FFBBlock>")
Public Function Highlight(ByVal highlightcolor As System.Drawing.Color, ByVal fontstyle As FontStyle, ByVal WordsToFind As String)
      Dim FoundAtPosition As Integer
      If WordsToFind IsNot Nothing Then
          FoundAtPosition = GenCodeText.Find(WordsToFind, RichTextBoxFinds.None)
          Do Until FoundAtPosition < 0
              ' Highlight text
              ' Search next occurrence
              GenCodeText.SelectionColor = highlightcolor
              GenCodeText.SelectionFont = New Font("tahoma", 8, fontstyle)
              FoundAtPosition = GenCodeText.Find(WordsToFind, FoundAtPosition + 1, RichTextBoxFinds.None)

          Loop
      End If


this sub is highlighting around 1000 words inside my text"GenCodeText"....sometimes it is working and sometimes it is not......if i minimize the my text.....this error completely unseen.
so is there any way to exclude this error or to stop highlighting if it will happen or is there another better way to highlight inside RichTextBox.
Posted

1 solution

You could try changing this:
If WordsToFind IsNot Nothing Then

...into this:
If String.IsNullOrWhiteSpace(WordsToFind) Then

Could you also add the error details you get? This isn't clear right now.

Good luck!
 
Share this answer
 
Comments
Ahmed.ganainy 14-Dec-12 14:52pm    
it is not the issue as you see in the below:
http://imageshack.us/photo/my-images/690/errorik.png/
the sub identified the word and its location but ...i don't know."System.ComponentModel.Win32Exception was unhandled
"
and for the same code sometimes i see this issue and sometimes i don't see...how come??
E.F. Nijboer 17-Dec-12 3:58am    
That's a pretty strange error at that point. Could it be the Highlight method is called very often?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900