Re: Change the font color
Use the RichTextBox control when you have to display differently formatted text in the same box.
Re: Change the font color
Thank u for ur response.
After posting the query I have placed the Rich Text box ctrl.
I am able to color the text from different text boxes differently. But the problem is when the text is sent from the same text box for the second time, every thing is changing its color to the color of the present line.
Thanks
Harini
Re: Change the font color
The following code changes the color in a rich text box, preserving the previous color. I hope you can modify it to suit your needs.
private Sub Command1_Click()
Dim OldLen as Integer
'Save the length of the text
OldLen = len(RichTextBox1.Text)
'set the insertion point at the end of the the rich text box
RichTextBox1.SelStart = OldLen
'Insert a newline character at the end, you could use vbNewLine
RichTextBox1.SelText = vbCrLf
'Compute the newlength. It is basically oldlen + 2
OldLen = len(RichTextBox1.Text)
'This adds the new text at the end of what is already in the rtb.
RichTextBox1.SelText = Text1.Text
'Selection starts at the old length (just before the new text)
RichTextBox1.SelStart = OldLen
'You know this...
RichTextBox1.SelLength = len(Text1.Text)
'Change the color depending upon the choice
If Option1.Value = true then RichTextBox1.SelColor = vbRed else RichTextBox1.SelColor = vbBlue
'Finally remove the selection
RichTextBox1.SelLength = 0
End Sub
Re: Change the font color
Hello Shree,
Thank you for the solution. I am trying to implement it my robust code. If I have any more doubts I will get back to you
Thanks
Harini