|
-
Jan 24th, 2000, 05:53 AM
#1
Thread Starter
Lively Member
How do I change part of a RTB control's text color? For instance
<Andy> hello
<Andy> how are you?
I just want to change <Andy> to a different color on each new line?
-
Jan 24th, 2000, 06:20 AM
#2
Junior Member
You can do something like this:
rtb.SelStart = 1 'starting position
rtb.SelLength = 5 'length
rtb.SelColor = 255 'your color
rtb.SelLength = 0 'remove the selection
You can use InStr() function to determine starting position and length of your part of the text programmatically, if you need.
Regards, Vlad
-
Jan 24th, 2000, 06:37 AM
#3
Thread Starter
Lively Member
vlad
I tried that code, and it works fine, but only for the first occurrence of <Andy> how do i do it for all occurrences of <Andy>?
Thanks...
ande211
-
Jan 24th, 2000, 08:07 AM
#4
Member
You can treat is as an HTML code, There is a code on this site somewhere, that Converts < > and everything in between into another color. Look for HTMLTag.
-
Jan 24th, 2000, 08:17 AM
#5
Lively Member
Hi Ande.
Here's code that does what you want (i.e. change <Andy> to red.)
Name your rich text box control rtb and put a command button on your form.
Paste this code into the VB Editor:
Code:
Option Explicit
Private Sub Command1_Click()
Dim stTemp As String
Dim bEnd As Boolean
stTemp = "<Andy>"
Do Until InStr(rtb.Text, stTemp) = 0
If Len(stTemp) = Len(rtb.Text) Then
If Right(stTemp, 6) <> "<Andy>" Then
Exit Sub
Else
bEnd = True
End If
End If
With rtb
.SelStart = Len(stTemp) - 6
.SelLength = 6
.SelColor = 255
End With
If bEnd = False Then
Do
stTemp = stTemp & Mid(rtb.Text, Len(stTemp) + 1, 1)
Loop Until Right(stTemp, 6) = "<Andy>" Or Len(stTemp) = Len(rtb.Text)
Else
Exit Sub
End If
Loop
End Sub
Private Sub Form_Load()
rtb.Text = "<Andy> Hello" & vbCrLf & "<Andy> How are <Andy>you today? <Andy>"
End Sub
All the best.
Chris
[This message has been edited by ChrisJackson (edited 01-24-2000).]
-
Jan 24th, 2000, 10:17 AM
#6
Junior Member
hey, I had the exact same problem, and I found a very simple answer.
say you want to send certian text to the rtb, like when <Joe> says something...
with RTB1
.selstart = len(.text)
.selcolor = vbBlue
.seltext = "<Joe> "
.selstart = len(.text)
.selcolor = vbRed
.seltext = " hey this works great!"
end with
you can easily make a sub for it so you can do something like Call Color(vbRed,"Hey") or something like that, thats what I did.
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
|