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.
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

JuiletteConnect With a Mentor Commented:
Answered in the above comments.
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

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.

All Courses

From novice to tech pro — start learning today.