Rich Text

I am makeing a chat program and I am going to add all the text that was sent a richtextbox and I need to make the text that is sent a different color then the text that is recived. All I really need to know then is how to add a new line with a different color then the line before it.
mistawallAsked:
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.

JuiletteCommented:
Sub PrintMessage(MessageText As String, MessageColor As Long, RTFBox As RichTextBox)
RTFBox.SelStart = Len(RTFBox.Text)
RTFBox.SelText = MessageText
RTFBox.SelStart = RTFBox.SelStart - Len(MessageText)
RTFBox.SelLength = Len(MessageText)
RTFBox.SelColor = MessageColor
RTFBox.SelStart = Len(RTFBox.Text)
End Sub

Usage:
PrintMessage "This is a sample message in RED." & vbCrLf, RGB(255, 0, 0), RichTextBox1

If you want a multicolored line use like this:
PrintMessage "Green part ", RGB(0, 255, 0), RichTextBox1
PrintMessage "Blue part" & vbCrLf, RGB(0, 0, 255), RichTextBox1

Note you put vbCrLf only when you want to end the line.
Of course, you can use QBColor instead of RGB, or system color constants, or the color hex value.

0
JuiletteCommented:
Answered in the above comments.
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
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.