Link to home
Start Free TrialLog in
Avatar of mistawall
mistawall

asked on

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.
Avatar of Juilette
Juilette

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.

ASKER CERTIFIED SOLUTION
Avatar of Juilette
Juilette

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial