devxlogo

Providing Multiple Colors

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. 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. 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).

devx-admin

Share the Post: