I need to change the color of each line of a rich text box as each line of code is added. Could someone please help me out with some code.
This is for a chat program.
Printable View
I need to change the color of each line of a rich text box as each line of code is added. Could someone please help me out with some code.
This is for a chat program.
I don't know what your chat program looks like but here's an example for you to try out.
Start a new standard EXE application. Add a RichTextBox to the form. Put an ordinary TextBox under it and add a command button.
You type a line of text in the ordinary TextBox and hit the CommandButton. The text you have typed is then added to the RTF-box.
Put the following code in the Click event of the CommandButton:
Play around with it for a while.Code:Private Sub Command1_Click()
Randomize
With RichTextBox1
.SelStart = Len(.Text)
.SelColor = QBColor(Int(Rnd * 16))
.SelText = Text1.Text & vbCrLf
Text1 = ""
Text1.SetFocus
End With
End Sub
Good luck!
I would suggest you randomize the QBColor out of 15 instead of 16. That way, you will not get stuck with the colour white.
Code:.SelColor = QBColor(Int(Rnd * 15))