... Rich Text Box Changing color of text?

Is there a way to change the color of the text in a rich text box? ...

Rtxt.text = "Hello" & vbCrLf <- in blue
Rtxt.text = Rtxt.text & "Good Bye" & vbCrLf <- in red

?
LVL 10
ThaSmartUnoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mcriderCommented:
You need to use SelColor.  Here's an example:


With RichTextBox1
    .SelStart = 0
    .SelColor = QBColor(1) ' blue
    .Text = "Hello" & vbCrLf '<- in blue
    iVal = Len(.Text)
    .Text = .Text & "Good Bye" & vbCrLf '<- in red
    .SelStart = iVal
    .SelLength = Len(.Text)
    .SelColor = QBColor(4) ' red
    .SelLength = 0
End With


Cheers!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mark2150Commented:
On my web page is a little app (with source) called WHAT2DO. It's a daily calendar. The events for the day have a RTB that you can change colors, fonts, & alignment. Grab a copy and you'll see how it's done.

visit: www.cyberchute.com/rvbus/madmark

M
0
ThaSmartUnoAuthor Commented:
Thanks
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

ThaSmartUnoAuthor Commented:
well there is one problem ... Im using this is a chatter i have ... and when i change the color it works.  But when I add anything else to the text box it will make it change back to the normal color.... do you know what I could do?
0
mcriderCommented:
Add text to the textbox by using setting the SelStart, SelLength and SelText properties...

For example:


Dim iVal As Long

With RichTextBox1
    .Text = ""
    .SelStart = 0
    .SelLength = 0
    .SelColor = QBColor(1) ' blue
    .SelText = "Hello" & vbCrLf '<- in blue
   
    iVal = Len(.Text)
    .SelStart = iVal
    .SelLength = 0
    .SelText = "Good Bye" & vbCrLf '<- in red
    .SelStart = iVal
    .SelLength = Len(.Text)
    .SelColor = QBColor(4) ' red
    .SelLength = 0
   
   
    iVal = Len(.Text)
    .SelStart = iVal
    .SelLength = 0
    .SelText = "More Text" & vbCrLf '<- in red
    .SelStart = iVal
    .SelLength = Len(.Text)
    .SelColor = QBColor(6) ' red
    .SelLength = 0
   
End With

0
ThaSmartUnoAuthor Commented:
Thank you!  =)

Id give you more points ... but I don't have much to share.  Heh
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.