CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    tdeltax Guest

    [RESOLVED] formatting colors of Richtextbox control

    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


  2. #2
    Join Date
    Oct 2001
    Posts
    55

    formatting colors of Richtextbox control

    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


  3. #3
    Join Date
    Sep 2001
    Posts
    11

    Re: formatting colors of Richtextbox control

    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


  4. #4
    tdeltax Guest

    Re: formatting colors of Richtextbox control

    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.


  5. #5
    Join Date
    Oct 2001
    Posts
    55

    Re: formatting colors of Richtextbox control

    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.


  6. #6
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: formatting colors of Richtextbox control

    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

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

Featured