Results 1 to 5 of 5

Thread: [RESOLVED] Rich Text Box Problem.. Pls Help..

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2008
    Posts
    43

    Resolved [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...

  2. #2
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    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

    IIF(Post.Rate > 0 , , )

  3. #3
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    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.

  4. #4
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Rich Text Box Problem.. Pls Help..

    To autoscroll I always put the .SelStart code in the Change() event. Ex:

    vb Code:
    1. Private Sub RTB_Change()
    2.     RTB.SelStart = Len(.Text)
    3. 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:
    1. With RTB
    2.     .SelStart = Len(.Text) 'Move to end.
    3.     'Blue if it is the user's message, red if it is from someone else.
    4.     .SelColor = IIf(strSender = strMyUsername, RGB(0, 0, 128), RGB(128, 0, 0))
    5.     'Set bold to true.
    6.     .SelBold = True: .SelItalic = False: .SelUnderline = False
    7.     'Add username:
    8.     .SelText = strSender & ": "
    9.     .SelBold = False
    10.     .SelColor = vbBlack
    11.     'Add chat message.
    12.     .SelText = ChatMessageText & vbCrLf
    13. End With

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2008
    Posts
    43

    Re: Rich Text Box Problem.. Pls Help..

    Thank you very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width