How to color the words in Rich Text box automatically like VB Editor?
Posted on January 4, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 'Controls - How to color the words in Rich Text box automatically like VB Editor? Private Sub Command1_Click() Dim OldSelStart As Long RichTextBox1.TextRTF = "Hello World" ' Clear formatting and change text to Hello World OldSelStart = RichTextBox1.SelStart ' Remember old SelStart ' Color the Hello: RichTextBox1.SelStart = InStr(RichTextBox1.Text, "Hello") - 1 RichTextBox1.SelLength = Len("Hello") RichTextBox1.SelColor = vbRed ' Color the World: RichTextBox1.SelStart = InStr(RichTextBox1.Text, "World") - 1 RichTextBox1.SelLength = Len("World") RichTextBox1.SelColor = vbBlue ' Clear selection: RichTextBox1.SelStart = OldSelStart End Sub |