Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
the error is coming from highlight sub for richtextbox:
 

        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 14-Dec-12 3:27am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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!
  Permalink  
Comments
Ahmed.ganainy at 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 at 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)



Advertise | Privacy | Mobile
Web02 | 2.8.140709.1 | Last Updated 14 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid