|
-
Jun 25th, 2000, 12:55 PM
#1
Thread Starter
Fanatic Member
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
-
Jun 25th, 2000, 12:59 PM
#2
PowerPoster
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]
-
Jun 25th, 2000, 01:14 PM
#3
Hyperactive Member
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
-
Jun 26th, 2000, 03:04 AM
#4
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
-
Jun 26th, 2000, 03:10 AM
#5
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
-
Jun 26th, 2000, 06:19 AM
#6
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
-
Jun 26th, 2000, 07:32 AM
#7
Thread Starter
Fanatic Member
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.
-
Jun 26th, 2000, 11:21 AM
#8
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|