Click to See Complete Forum and Search --> : formatting colors of Richtextbox control
tdeltax
October 18th, 2001, 04:48 AM
Hi
i am using the richtextbox to display a log file i want the different lines of the log to be dislayed in different colors depending on their log status.
i tried it out in rtb but the rtb color changes. can u please help me out with this or suggest a better control to display the log file with some BMP's inserted
tdeltax
October 18th, 2001, 04:48 AM
Hi
i am using the richtextbox to display a log file i want the different lines of the log to be dislayed in different colors depending on their log status.
i tried it out in rtb but the rtb color changes. can u please help me out with this or suggest a better control to display the log file with some BMP's inserted
baronq
October 18th, 2001, 09:54 AM
I don't know what you've tried in rtb, but I guess you haven't tried it with selection. Just select a line, call selcolor.
BaronQ
tdeltax
October 18th, 2001, 11:49 PM
actually i got ur point but the log display is done at runtime without any manual selection.
following is the code i have used
Dim strchk As String
Set swbuff = sfile.OpenTextFile("c:\windows\desktop\file1.rtf", ForReading, True, TristateUseDefault)
strbuff = swbuff.ReadAll
strarr = Split(strbuff, vbNewLine)
For i = 0 To UBound(strarr)
strchk = Left(strarr(i), 1)
Select Case strchk
Case "F"
RTB.Refresh
RTB.Text = RTB.Text & Right(strarr(i), Len(strarr(i)) - 2) & vbCrLf
RTB.SelStart = Len(RTB.Text) - Len(strarr(i))
RTB.SelLength = Len(strarr(i)) - 2
RTB.SelColor = vbRed
RTB.SelLength = 0
Case "D"
RTB.Refresh
RTB.Text = RTB.Text & Right(strarr(i), Len(strarr(i)) - 2) & vbCrLf
RTB.SelStart = Len(RTB.Text) - Len(strarr(i))
RTB.SelLength = Len(strarr(i)) - 2
RTB.SelColor = vbYellow
RTB.SelLength = 0
Case "S"
RTB.Refresh
RTB.Text = RTB.Text & Right(strarr(i), Len(strarr(i)) - 2) & vbCrLf
RTB.SelStart = Len(RTB.Text) - Len(strarr(i))
RTB.SelLength = Len(strarr(i)) - 2
RTB.SelColor = vbBlue
RTB.SelLength = 0
End Select
i am parsing each line based on the suffix, selecting the line programmatically and then changing its color. but instead of color of a sigle line being changed the color of the full rtb is getting changed.
tdeltax
October 18th, 2001, 11:49 PM
actually i got ur point but the log display is done at runtime without any manual selection.
following is the code i have used
Dim strchk As String
Set swbuff = sfile.OpenTextFile("c:\windows\desktop\file1.rtf", ForReading, True, TristateUseDefault)
strbuff = swbuff.ReadAll
strarr = Split(strbuff, vbNewLine)
For i = 0 To UBound(strarr)
strchk = Left(strarr(i), 1)
Select Case strchk
Case "F"
RTB.Refresh
RTB.Text = RTB.Text & Right(strarr(i), Len(strarr(i)) - 2) & vbCrLf
RTB.SelStart = Len(RTB.Text) - Len(strarr(i))
RTB.SelLength = Len(strarr(i)) - 2
RTB.SelColor = vbRed
RTB.SelLength = 0
Case "D"
RTB.Refresh
RTB.Text = RTB.Text & Right(strarr(i), Len(strarr(i)) - 2) & vbCrLf
RTB.SelStart = Len(RTB.Text) - Len(strarr(i))
RTB.SelLength = Len(strarr(i)) - 2
RTB.SelColor = vbYellow
RTB.SelLength = 0
Case "S"
RTB.Refresh
RTB.Text = RTB.Text & Right(strarr(i), Len(strarr(i)) - 2) & vbCrLf
RTB.SelStart = Len(RTB.Text) - Len(strarr(i))
RTB.SelLength = Len(strarr(i)) - 2
RTB.SelColor = vbBlue
RTB.SelLength = 0
End Select
i am parsing each line based on the suffix, selecting the line programmatically and then changing its color. but instead of color of a sigle line being changed the color of the full rtb is getting changed.
John G Duffy
October 19th, 2001, 09:54 AM
This simple sample works for me, highlighting only certain text of a line
option Explicit
private Sub Command1_Click()
Dim oldLen as Long
oldLen = len(rtb.Text)
rtb.Text = rtb.Text & "new Text"
rtb.SelStart = oldLen
rtb.SelLength = len(rtb.Text) - oldLen
rtb.SelColor = vbRed
rtb.SelStart = 1
End Sub
John G
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.