Results 1 to 8 of 8

Thread: I give Up Rich Text Control

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523
    How can I make this multicolor in rich text box?
    "1) C:\WINDOWS\Desktop\test.zip - No files were found due to bad decryption password(s)"

    I want the "1)" to be let's say in yellow
    "C:\windows\desktop\test.zip" in red
    the rest in blue

    Thanks in advance

  2. #2
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Something like that:
    Code:
    RTF.SelColor = RGB( 255, 255, 0 ) 'Yellow
    RTF.SelText = "1) "
    RTF.SelColor = 255 'Red
    RTF.SelText = "C:\WINDOWS\Desktop\test.zip"
    RTF.SelColor = RGB( 0, 0, 255 ) 'Blue
    RTF.SelText = " - No files were found due to bad decryption password(s)"
    Should work


    [Edited by Fox on 06-27-2000 at 12:22 AM]

  3. #3
    Hyperactive Member
    Join Date
    Dec 1999
    Posts
    321
    Just wanted to say that that code won't work.
    Signed, Rodik ([email protected])
    Programmer,usesVB6ED
    ===========================
    Copyright©RodikCo,2002.

    Dont mind this signature ;] Its old

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

    Don't give up

    Try something like this:
    Code:
    Private Sub Command1_Click()
        Dim intPos As Integer
        Dim intOldPos As Integer
        
        With RichTextBox1
            'Get position of the "1)"
            intPos = InStr(.Text, "1)")
            intPos = intPos + Len("1)")
            If intPos Then
                .SelStart = 0
                .SelLength = intPos
                .SelColor = vbYellow
            End If
            'Memorize last position
            intOldPos = intPos
            
            'Get position of the filename
            intPos = InStr(intOldPos, UCase(.Text), "TEST.ZIP")
            intPos = intPos + Len("TEST.ZIP")
            If intPos Then
                .SelStart = intOldPos
                .SelLength = intPos - intOldPos
                .SelColor = vbRed
            End If
            'Colorize the rest of the text with blue
            .SelStart = intPos + 1
            .SelLength = Len(.Text) - intPos
            .SelColor = vbBlue
            
            .SelStart = Len(.Text)
        End With
    End Sub

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

    Go Generic...

    Or better yet, here is the generic function you can use to colorize te words in the RichTextBox:
    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 you can call this Sub Routine like this:

    Code:
    Private Sub Command1_Click()
        Dim strWords As String
        
        strWords = "1)"
        ColorWords RichTextBox1, strWords, vbYellow
        
        strWords = "C:\WINDOWS\Desktop\test.zip"
        ColorWords RichTextBox1, strWords, vbRed
        
        strWords = "- No files were found due to bad decryption password(s)"
        ColorWords RichTextBox1, strWords, vbBlue
    End Sub

  6. #6
    Guest
    Code:
    Private Sub Form_Load ()
     With RichTextBox1
         .Text = "Welcome to the RichTextBox Sample Source Code!"
         .SelStart = 0
         .SelLength = Len(.Text)
         .SelFontName = "Arial"
         .SelFontSize = 10
         .SelAlignment = rtfCenter
         .SelStart = InStr(.Text, "RichTextBox") - 1
         .SelLength = Len("RichTextBox")
         .SelFontName = "Courier New"
         .SelColor = vbBlue
         .SelStart = InStr(.Text, "Sample Source Code") - 1
         .SelLength = 4
         .SelFontName = "Courier New"
         .SelUnderline = True
         .SelStart = .SelStart + 1
         .SelLength = 1
         .SelColor = vbRed
         .SelStart = .SelStart + 1
         .SelLength = 1
         .SelColor = vbBlue
         .SelStart = .SelStart + 1
         .SelLength = 1
         .SelColor = vbGreen
         .SelStart = 0
         .SelLength = 0
      End With
    End Sub

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523
    Thanks Serge for the function. Works almost perfectly (I had to change it just a little bit for the purposes of my app)

    Thanks again.

  8. #8
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    You're right, I forgot to put in the text... this works:

    Code:
    With RichTextBox1
        .SelColor = RGB(255, 255, 0)   'Yellow
        .SelText = "1) "
        .SelColor = 255 'Red
        .SelText = "C:\WINDOWS\Desktop\test.zip"
        .SelColor = RGB(0, 0, 255)   'Blue
        .SelText = " - No files were found due to bad decryption password(s)"
    End With

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