|
-
Apr 30th, 2008, 11:28 PM
#1
Thread Starter
Member
[RESOLVED] Rich Text Box Problem.. Pls Help..
Problem 1 :
I'm using RT for a chat application and I want it automatically scroll til the end of the conversation so that the recent conversation is visible. Or else we have to scroll till the end and then read.
How can I achieve this??
Problem2 :
I want to use multiple coloures. i.e- Other username in one colour and my username in another colour. Like (Yahoo Mess).
How can I achieve this...
Waiting for your help.
Thanks...
-
Apr 30th, 2008, 11:55 PM
#2
Frenzied Member
Re: Rich Text Box Problem.. Pls Help..
Answer 1
esiest :
Code:
RichTextBox1.SelStart = Len(RichTextBox1.Text)
RichTextBox1.SetFocus
Answer 2
Code:
RichTextBox1.SelStart = 2
RichTextBox1.SelLength = 2
RichTextBox1.SelColor = vbRed
RichTextBox1.SelColor = RGB(255, 255, 255)
Steps
1st : Goto start of the required text
2nd : Select required text by giving SelLength
3rd : set the selected text's color
1. using standard color constatnts
2. using RGB combination
You might link a color chooser to get the color also
-
Apr 30th, 2008, 11:55 PM
#3
Re: Rich Text Box Problem.. Pls Help..
This may be counter intuitive but you could always reverse the concatination when you add messages to the RTB, ie the lastest message will always be at the top of the RTB and therefore always visible.
Instead of something like
Code:
rtb.Text = rtb.Text & strMessage & vbCrLf
you'd use
Code:
rtb.Text = strMessage & vbCrLf & rtb.Text
A more intuitive approach would be to set the rtbs .Selstart Property to the Length of the rtb's Text property after you've added the latest message.
For colouring, this thread http://www.vbforums.com/showthread.p...&highlight=rtb may help you.
Edit: I see zeezee got there before me.
-
May 1st, 2008, 01:35 AM
#4
Re: Rich Text Box Problem.. Pls Help..
To autoscroll I always put the .SelStart code in the Change() event. Ex:
vb Code:
Private Sub RTB_Change() RTB.SelStart = Len(.Text) End Sub
And for colors on the username, a simple IIF() statement can work. Let's say you have your (the user's) username in a variable `strMyUsername` and the person who is sending the message in another variable `strSender`, you could do:
vb Code:
With RTB .SelStart = Len(.Text) 'Move to end. 'Blue if it is the user's message, red if it is from someone else. .SelColor = IIf(strSender = strMyUsername, RGB(0, 0, 128), RGB(128, 0, 0)) 'Set bold to true. .SelBold = True: .SelItalic = False: .SelUnderline = False 'Add username: .SelText = strSender & ": " .SelBold = False .SelColor = vbBlack 'Add chat message. .SelText = ChatMessageText & vbCrLf End With
-
May 1st, 2008, 05:18 AM
#5
Thread Starter
Member
Re: Rich Text Box Problem.. Pls Help..
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
|