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

See also  How to Create and Deploy QR Codes Online: A Comprehensive Guide
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist