Can I get a control similar to the textboxes in Excel for VB

Syed Irtaza Ali
Syed Irtaza Ali used Ask the Experts™
I am looking for a text box control that can display text
like this

[in RED]Alert: [in Blue]Please update your [in Green]settings

[in RED] means the following text would be in Red colour
[in Blue] means the following text would be in blue colour
[in Green] means the following text would be in Green colour

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

RichTextBox Control might be the answer.
Syed Irtaza AliLead Software Architect


How would i do it then, using the RichTextBox?


Honestly, I never used it, but as I understand from help file: You have to create a rich text document (or text with rich formating) and assign it Text property.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Probably it's not simple. First, you should master formating text using Rich Text capabilites.

If you create a document in MSWord and color some words or change size, etc... and copy that text into VB rich text control it will keep formating. Probably, you could do that dynamically, but I have no idea how to apply formating to string.

Actually, the richtextbox is simple to add coloring to it in various places.  The problem becomes when you add further data (more lines of text) to it, you either need to reformat the whole thing or resort to adding the line via RTF Commands.

If you have relatively static text (text that doesn't change once you initially set it, but that text can be dynamically loaded), you can do something like this:

with RichTextBox1
  .SelStart = 0
  .sellength = 4
  .selcolor = vbBlue
  .selstart = 6
  .sellength = 4
  .selcolor = vbRed
  .selstart = 11
  .sellength = 6
  .selcolor = vbgreen
  .selstart = 18
  .sellength = 4
  .selcolor = vbYellow

end with

And so on.  Now you can find the text you are looking for instead of hard-codding the values using Instr, etc.
In order to use this you must add a component reference to Microsoft Rich TextBox in your project.
Syed Irtaza AliLead Software Architect


ok twalgrave, now when this is done, could i do drag and drop with the highlighted text easily or will that be a hard part. Basically after this is done (the colour mechanism), I should be able to identify the start and end of text respective to its colour scheme. Now if the user selects any char of maybe blue colour, then the whole text in blue would be dragged and dropped in a list or text box.

Note: I would like to use distinct colours for every text, and most probably have 12 colours at most (meaning 12 sentences)

[How many chocolates] * [How many IceCreamz]

so is that possible?

Sorry for the late reply, just came across this wile doing cleanup of my mailbox.  While the original question was answered, I'd like to answer the added question of dragging/dropping if you still need help with this.
STD Cleanup Script
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- answered by twalgrave

Please leave any comments here within the
next seven days.


Cleanup Volunteer
Syed Irtaza AliLead Software Architect


Thanks, but my question was partially solved.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial