Providing Multiple Colors

Question:
I having trouble using strings and text. I am writing a document creation system and all the text in between the “<" char. and the ">” char. would be red. All other text would be red.

Answer:
The first problem is getting multiple colors in a text box. You’ll have to use a different control from the standard text box, since it doesn’t support multiple colors. Take a look at my File Archives area for a selection of enhanced text boxes. If you’re using VB4.0 you can use the RichTextBox control. You’d want to use the Instr Function to check each new line of text, if you find a “<" character you'd remember the position (Instr returns that as an Integer) and then start a fresh Instr from there to find the ">” character. Now you know where your string to change color lies… you’d then use the SelStart and SelLength the select that string and set its color property (I believe it’s the Foreground property) to red (or whichever color you like).

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: