emresamisuzer
asked on
Richtextbox text color
I need to change the color of the added line color, but after three repetitions all line colors become the same.
You may see the function that adds new line to the richtextbox and assigns color to it.
When I run it four times with the settings you may see except the first line all lines become red.
You may see the function that adds new line to the richtextbox and assigns color to it.
When I run it four times with the settings you may see except the first line all lines become red.
Private Sub myworkerclass_AddDateTime(ByVal message As String, ByVal thecolor As System.Drawing.Color) Handles myworkerclass.AddDateTime
Me.rtb_messages.Text = message & vbCrLf & Me.rtb_messages.Text
Me.rtb_messages.Select(0, message.Length)
Me.rtb_messages.SelectionColor = thecolor
End Sub
myworkerclass_AddDateTime("Test1!", Color.Purple)
myworkerclass_AddDateTime("Test2!", Color.Red)
myworkerclass_AddDateTime("Test3!", Color.YellowGreen)
myworkerclass_AddDateTime("Test4!", Color.Tomato)
You can also do it this way:
Private Sub myworkerclass_AddDateTime(ByVal message As String, ByVal thecolor As System.Drawing.Color) Handles myworkerclass.AddDateTime
Me.rtb_messages.SelectionStart = Me.rtb_messages.TextLength
Me.rtb_messages.SelectionColor = thecolor
Me.rtb_messages.SelectedText = message & vbCrLf
End Sub
ASKER
Thanks for your responses but I need the appended text to be appended at the top line of the richtextbox. That is why I use the code:
Me.rtb_messages.Text = message & vbCrLf & Me.rtb_messages.Text
Me.rtb_messages.Text = message & vbCrLf & Me.rtb_messages.Text
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Mine would be:
Private Sub myworkerclass_AddDateTime(ByVal message As String, ByVal thecolor As System.Drawing.Color) Handles myworkerclass.AddDateTime
Me.rtb_messages.SelectionStart = 0
Me.rtb_messages.SelectionLength = 0
Me.rtb_messages.SelectionColor = thecolor
Me.rtb_messages.SelectedText = message & vbCrLf
End Sub
Try to change you sub to this:
Open in new window