This is what my code looks like
Form1.GRQ.AddItem txtRequest.Text & (" - Pending")
I just want to change the ( – Pending) part to red so it appears red next to the black text in the listbox. any ideas?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Using regular VB6 controls, unfortunately, you can’t do this. You can change the color of all the text of a textbox/listbox/label using
.ForeColor, but not parts of it, and that’s really no good for you. Thankfully, there are two solutions:The first is to continue to use the listbox as you have it, but add in a caption with red text reading ” – Pending” next to the text you want. It’s not pretty, but you can make it work.
The better solution is to get more familiar with the RichTextBox control. This will only work if you have the Professional or Enterprise versions of VB6, though. Assuming you do, on the VB6 menu, click Project -> Components, and then in the new window that pops up, under the Controls tab, check “Microsoft Rich TextBox Control 6.0” and then click OK. The RichTextBox option should appear on the Toolbox, you can add it to the form like any other object, and it’ll act like a combination listbox/textbox… it’s very useful. If you want some documentation on it, check out the MSDN.
Unfortunately, RichTextBox kinda stinks in terms of changing the color of text. It can be done, but not with a simple command. You have to find the text you want, select it, and then set the color. (This also goes if you want to change the color of all the text – you have to select it all first.) Anyway, the way to do that would be:
RichTextBox1.SelStart = RichTextBox1.Find(" - Pending")RichTextBox1.SelLength = 10RichTextBox1.SelColor = vbRedI hope all this helps. Best of luck!