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
本文介绍了一种在RichBox中实现特定关键字高亮显示的方法。通过使用RichTextBox的Find和SelectionColor属性,代码能够在文本框中搜索并改变指定关键字的颜色,实现文本的视觉突出。这一技巧对于开发带有语法高亮功能的文本编辑器或代码查看器非常实用。
361

被折叠的 条评论
为什么被折叠?



