Results 1 to 5 of 5

Thread: Need help with rich textbox with colors things look please

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    219

    Post

    ok here what i want to do like if there a word in the rtf Called Port I want the word port to be Blue and other words can someone in here please help me with this?

  2. #2
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527

    Post

    i have already answered this question, try searching next time

    anyway, here it is for you


    Code:
    RichTextBox1.Text = "Port: LPT1" 'Whatever the text is
    RichTextBox1.SelStart = 0 'Where the other text before port ends
    RichTextBox1.SelLength = 4 'the length of "Port"
    RichTextBox1.SelColor = vbBlue 'Set the color of selected text
    RichTextBox1.SelStart = Len(RichTextBox1.Text) 'Goto end of text box



    ------------------
    david
    Teenage Programmer


  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    219

    Post

    hey what do i use this code in it not working in the change code thing

    RichTextBox1.Text = "Port: LPT1" 'Whatever the text is

    Code:
    RichTextBox1.SelStart = 0 'Where the other text before port ends
    RichTextBox1.SelLength = 4 'the length of "Port"
    RichTextBox1.SelColor = vbBlue 'Set the color of selected text
    RichTextBox1.SelStart = Len(RichTextBox1.Text) 'Goto end of text box

  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    You can use this function I wrote:

    Code:
    Public Sub ColorWords(pRich As RichTextBox, pWord As String, pColor As OLE_COLOR)
        Dim iPos As Integer
        
        With pRich
            iPos = InStr(iPos + 1, .Text, pWord, vbTextCompare)
            Do While iPos <> 0
                .SelStart = iPos - 1
                .SelLength = Len(pWord)
                .SelColor = pColor
                iPos = InStr(iPos + 1, .Text, pWord, vbTextCompare)
            Loop
        End With
    End Sub
    Then call this sub routine like this:

    ColorWords RichTextBox1, "Port", vbBlue

    ------------------

    Serge

    Senior Programmer Analyst
    [email protected]
    [email protected]
    ICQ#: 51055819

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 1999
    Posts
    219

    Post

    Thanx Man That Otehr GuyDid Not Help Me With Crap You Help Alot It was Just What I Was Looking For

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