-
Feb 8th, 2007, 10:49 AM
#1
Thread Starter
Lively Member
[RESOLVED] Coloring text in Rich Text Box for chat program.
I have a rich text box that displays text from a chat channel. So each time text is send to the channel it's added, like this:
rtbText.text = rtbText.text + Incoming
rtbText.SelStart = Len(rtbText.Text)
I want to give a color to the Incoming string and this piece of text will stay colored in the Rich Text Box and will not be changed after a new message has been colored in a different color.
How can this be done?
-
Feb 8th, 2007, 10:57 AM
#2
Re: Coloring text in Rich Text Box for chat program.
If the string never changes color, won't you in very short order, run out of colors?
-
Feb 8th, 2007, 11:06 AM
#3
Thread Starter
Lively Member
Re: Coloring text in Rich Text Box for chat program.
nah, there are 16 million, right
let me explain:
the Incoming string contains a message that is added to the RTB (with all messages), so it contains different text each time a new message comes in.
The message will be colored if its a join message or quit message, for example.
-
Feb 8th, 2007, 11:41 AM
#4
Re: Coloring text in Rich Text Box for chat program.
The best way to do it is when you receive the message. Here's an example.
VB Code:
Private Sub Command1_Click()
With RichTextBox1
.SelStart = Len(.Text) 'Go to end.
.SelBold = True 'Bold for username.
'Set color to blue for my username, red for someone else.
.SelColor = IIf(Username = MyUsername, vbBlue, vbRed)
.SelText = Username 'Enter their username.
.SelColor = 0 'Black.
.SelText = ": "
'Message text.
.SelColor = RGB(0, 123, 0) 'Green text?
.SelBold = False
.SelText = Message & vbCrLf
End With
End Sub
-
Feb 8th, 2007, 11:56 AM
#5
Thread Starter
Lively Member
Re: Coloring text in Rich Text Box for chat program.
ty,
your code colors the nick and the last message that has come in.
but the color of this particular line dissappears when a new message comes in, becuase the new message will be colored.
it's always the last line that has colors
it would be nice if the colors of the 1st messages stay, when new messages come in
-
Feb 8th, 2007, 12:00 PM
#6
Re: Coloring text in Rich Text Box for chat program.
That should not happen. Can you post your code?
-
Feb 8th, 2007, 12:04 PM
#7
Thread Starter
Lively Member
Re: Coloring text in Rich Text Box for chat program.
VB Code:
Public Sub ChannelIn()
rtbChannel.Text = rtbChannel.Text + Incoming & vbCrLf
With rtbChannel
.SelStart = Len(.Text) 'Go to end.
.SelBold = True 'Bold for username.
'Set color to blue for my username, red for someone else.
.SelColor = IIf(Nick = OwnNick, vbBlue, vbRed)
.SelText = Nick 'Enter their username.
.SelColor = 0 'Black.
.SelText = ": "
'Message text.
.SelColor = RGB(0, 123, 0) 'Green text? yes
.SelBold = False
.SelText = Incoming & vbCrLf
End With
rtbChannel.SelStart = Len(rtbChannel.Text) 'keeps incoming text at the end of textbox
End Sub
-
Feb 8th, 2007, 12:09 PM
#8
Re: Coloring text in Rich Text Box for chat program.
Remove or comment out the first line.
VB Code:
[COLOR=Red]rtbChannel.Text = rtbChannel.Text + Incoming & vbCrLf[/COLOR]
Also, if you do use something like this, always use & instead of + for strings. + is for numerical stuff, like adding 2 numbers. & is for adding one string to another.
-
Feb 8th, 2007, 12:14 PM
#9
Thread Starter
Lively Member
Re: Coloring text in Rich Text Box for chat program.
thanks, now all lines have color, not only the last
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
|