天天看點

VS-VB.net RichBox關鍵字高亮源代碼

RichBox 屬性Name : TextError

Private Function Colored_keywords(ByVal keywords As String) As Boolean

        Dim startText As Integer = 0
        Dim endText As Integer
        endText = TextError.Text.LastIndexOf(keywords)
        TextError.SelectAll()
        While startText < endText
            TextError.Find(keywords, startText, TextError.TextLength, RichTextBoxFinds.MatchCase)
            TextError.SelectionColor = Color.Brown
            startText = TextError.Text.IndexOf(keywords, startText) + 1
        End While
        Me.Refresh()
        Return True  
    End Function