Click to See Complete Forum and Search --> : Change the font color
Harini
June 22nd, 2001, 10:57 AM
Hello,
I have to change the color of the text in the text ctrl. If the text is received from one text box then its color should be different from the one received to the same the text box from another text box.
That is if the text is received from Text2 to text1 then it should be in red. If the text is received from Text3 to text1 then it should be green.
This is urgent, Please help me out
Thanks
Harini
shree
June 22nd, 2001, 11:28 AM
Use the RichTextBox control when you have to display differently formatted text in the same box.
Harini
June 22nd, 2001, 12:00 PM
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
shree
June 22nd, 2001, 12:07 PM
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
Harini
June 22nd, 2001, 01:55 PM
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
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.