|
-
June 22nd, 2001, 12:07 PM
#4
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|