Home All Groups Group Topic Archive Search About

How to change color line by line in a rich textbox?

Author
21 Feb 2006 1:26 PM
GY2
I want to step through the rows returned by my DataView, extract some values
from some of its columns and append them as separate lines to the text of
various rich textbox
controls while possibly changing the color of each new line.

It seems as though I should use the Lines property  but can't find a good
example. Below is my attempt to do it with the .Text property (which doesn't
work because no colors are displayed). I have also tried this with
..ForeColor instead of SelectionColor.

What I am doing wrong here and/or what is the right way to do it with
..Lines?

Imports System.Drawing.Color
Private Sub LoadRTB(ByRef myRTB As RichTextBox, ByVal dtWhichDate As Date)

     'set up DataView filter for the single specified date
    dvEventDataByDate.RowFilter = "EventDate = #" & dtWhichDate & "#"

    Dim myDRV As DataRowView  'a single row of the filetered DataView

    With myRTB

        For Each myDRV In dvEventDataByDate

            .SelectionColor = FetchColor  Left(myDRV("EventName"), 1))

            .Text = .Text & myDRV("EventName") & Space(1) &
myDRV("PatientID") & vbCrLf

        Next myDRV

    End With

End Sub



Private Function FetchColor(ByVal EventType$) As System.Drawing.Color

Select Case EventType$

Case "B"

    FetchColor = Cyan

Case "D"

    FetchColor = Blue

Case "I"

    FetchColor = Green

Case "K"

    FetchColor = Yellow

Case "L"

    FetchColor = Black

Case "N"

    FetchColor = Magenta

Case "S"

    FetchColor = Red

Case Else

    FetchColor = Black

End Select

End Function

Author
21 Feb 2006 8:25 PM
Ken Halter
"GY2" <2muchspam@wherever.com> wrote in message
news:uz%234qpuNGHA.3936@TK2MSFTNGP10.phx.gbl...
>I want to step through the rows returned by my DataView, extract some
>values
> from some of its columns and append them as separate lines to the text of
> various rich textbox

What was once "easy" is now "painful"...

This code, which works perfectly in VB4/5/6.....
'===============
Private Sub Form_Load()
   With RichTextBox1
      'Clear all
      .Text = ""
      .SelFontName = "Arial"
      .SelColor = vbRed
      .SelText = "This is red Arial text" & vbCrLf
      .SelBold = True
      .SelColor = vbBlue
      .SelFontName = "MS Sans Serif"
      .SelText = "This is MS Sans Serif, blue and bold" & vbCrLf
      .SelFontSize = 14
      .SelFontName = "Courier"
      .SelColor = vbGreen
      .SelText = "This is Courier bold, green and 14 points high" & vbCrLf
   End With
End Sub
'===============

....."migrates" to this mess (that almost works) in B#
'===============
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs
As System.EventArgs) Handles MyBase.Load
  With RichTextBox1
   'Clear all
   .Text = ""
   .SelectionFont = VB6.FontChangeName(.SelectionFont, "Arial")
   .SelectionColor = System.Drawing.Color.Red
   .SelectedText = "This is red Arial text" & vbCrLf
   .Font = VB6.FontChangeBold(.SelectionFont, True)
   .SelectionColor = System.Drawing.Color.Blue
   'UPGRADE_WARNING: Only TrueType and OpenType fonts are supported in
Windows Forms. Click for more:
'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="971F4DF4-254E-44F4-861D-3AA0031FE361"'
   .SelectionFont = VB6.FontChangeName(.SelectionFont, "MS Sans Serif")
   .SelectedText = "This is MS Sans Serif, blue and bold" & vbCrLf
   .SelectionFont = VB6.FontChangeSize(.SelectionFont, 14)
   'UPGRADE_WARNING: Only TrueType and OpenType fonts are supported in
Windows Forms. Click for more:
'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="971F4DF4-254E-44F4-861D-3AA0031FE361"'
   .SelectionFont = VB6.FontChangeName(.SelectionFont, "Courier")
   .SelectionColor = System.Drawing.Color.Lime
   .SelectedText = "This is Courier bold, green and 14 points high" & vbCrLf
  End With
End Sub
'===============

--
Ken Halter - MS-MVP-VB (visiting from VB6 world) - http://www.vbsight.com
Please keep all discussions in the groups..
Author
22 Feb 2006 9:14 PM
GY2
Jeeez! Almost sorry I asked. Thanks Ken.

Show quoteHide quote
"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:eyvmwTyNGHA.2696@TK2MSFTNGP14.phx.gbl...
> "GY2" <2muchspam@wherever.com> wrote in message
> news:uz%234qpuNGHA.3936@TK2MSFTNGP10.phx.gbl...
>>I want to step through the rows returned by my DataView, extract some
>>values
>> from some of its columns and append them as separate lines to the text of
>> various rich textbox
>
> What was once "easy" is now "painful"...
>
> This code, which works perfectly in VB4/5/6.....
> '===============
> Private Sub Form_Load()
>   With RichTextBox1
>      'Clear all
>      .Text = ""
>      .SelFontName = "Arial"
>      .SelColor = vbRed
>      .SelText = "This is red Arial text" & vbCrLf
>      .SelBold = True
>      .SelColor = vbBlue
>      .SelFontName = "MS Sans Serif"
>      .SelText = "This is MS Sans Serif, blue and bold" & vbCrLf
>      .SelFontSize = 14
>      .SelFontName = "Courier"
>      .SelColor = vbGreen
>      .SelText = "This is Courier bold, green and 14 points high" & vbCrLf
>   End With
> End Sub
> '===============
>
> ...."migrates" to this mess (that almost works) in B#
> '===============
> Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs
> As System.EventArgs) Handles MyBase.Load
>  With RichTextBox1
>   'Clear all
>   .Text = ""
>   .SelectionFont = VB6.FontChangeName(.SelectionFont, "Arial")
>   .SelectionColor = System.Drawing.Color.Red
>   .SelectedText = "This is red Arial text" & vbCrLf
>   .Font = VB6.FontChangeBold(.SelectionFont, True)
>   .SelectionColor = System.Drawing.Color.Blue
>   'UPGRADE_WARNING: Only TrueType and OpenType fonts are supported in
> Windows Forms. Click for more:
> 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="971F4DF4-254E-44F4-861D-3AA0031FE361"'
>   .SelectionFont = VB6.FontChangeName(.SelectionFont, "MS Sans Serif")
>   .SelectedText = "This is MS Sans Serif, blue and bold" & vbCrLf
>   .SelectionFont = VB6.FontChangeSize(.SelectionFont, 14)
>   'UPGRADE_WARNING: Only TrueType and OpenType fonts are supported in
> Windows Forms. Click for more:
> 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="971F4DF4-254E-44F4-861D-3AA0031FE361"'
>   .SelectionFont = VB6.FontChangeName(.SelectionFont, "Courier")
>   .SelectionColor = System.Drawing.Color.Lime
>   .SelectedText = "This is Courier bold, green and 14 points high" &
> vbCrLf
>  End With
> End Sub
> '===============
>
> --
> Ken Halter - MS-MVP-VB (visiting from VB6 world) - http://www.vbsight.com
> Please keep all discussions in the groups..
>
Author
21 Feb 2006 10:18 PM
Cerebrus99
Hi GY2,

Please see my reply to your post in the
Microsoft.Public.Dotnet.Framework.WindowsForms.Controls forum...

http://groups.google.com/group/microsoft.public.dotnet.framework.windowsforms.controls/browse_thread/thread/a078e2b6ab6db2df/49329f53c7952e62#49329f53c7952e62

Regards,

Cerebrus.
Author
22 Feb 2006 9:17 PM
GY2
Thanks Cerebrus. I only copied the post when I received no help here for a
while--too impatient (or desperate) I guess.Sorry for the double and thanks
for your help.

Show quoteHide quote
"Cerebrus99" <zorg***@sify.com> wrote in message
news:1140560283.384434.113960@g47g2000cwa.googlegroups.com...
> Hi GY2,
>
> Please see my reply to your post in the
> Microsoft.Public.Dotnet.Framework.WindowsForms.Controls forum...
>
> http://groups.google.com/group/microsoft.public.dotnet.framework.windowsforms.controls/browse_thread/thread/a078e2b6ab6db2df/49329f53c7952e62#49329f53c7952e62
>
> Regards,
>
> Cerebrus.
>
Author
23 Feb 2006 2:07 AM
Cerebrus
No problem, buddy, but did it work ???

Regards,

Cerebrus.