Results 1 to 3 of 3

Thread: Rich Text Box

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Adelaide - Australia
    Posts
    150
    I need to change the color of each line of a rich text box as each line of code is added. Could someone please help me out with some code.

    This is for a chat program.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    I don't know what your chat program looks like but here's an example for you to try out.

    Start a new standard EXE application. Add a RichTextBox to the form. Put an ordinary TextBox under it and add a command button.

    You type a line of text in the ordinary TextBox and hit the CommandButton. The text you have typed is then added to the RTF-box.

    Put the following code in the Click event of the CommandButton:
    Code:
    Private Sub Command1_Click()
        Randomize
        With RichTextBox1
            .SelStart = Len(.Text)
            .SelColor = QBColor(Int(Rnd * 16))
            .SelText = Text1.Text & vbCrLf
            Text1 = ""
            Text1.SetFocus
        End With
    End Sub
    Play around with it for a while.
    Good luck!

  3. #3
    Guest
    I would suggest you randomize the QBColor out of 15 instead of 16. That way, you will not get stuck with the colour white.
    Code:
    .SelColor = QBColor(Int(Rnd * 15))

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