473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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

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

Feb 21 '06 #1
5 16582
"GY2" <2m*******@wherever.com> wrote in message
news:uz****************@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..
Feb 21 '06 #2
Hi GY2,

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

http://groups.google.com/group/micro...329f53c7952e62

Regards,

Cerebrus.

Feb 21 '06 #3
GY2
Jeeez! Almost sorry I asked. Thanks Ken.

"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:ey**************@TK2MSFTNGP14.phx.gbl...
"GY2" <2m*******@wherever.com> wrote in message
news:uz****************@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..

Feb 22 '06 #4
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.

"Cerebrus99" <zo*****@sify.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Hi GY2,

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

http://groups.google.com/group/micro...329f53c7952e62

Regards,

Cerebrus.

Feb 22 '06 #5
No problem, buddy, but did it work ???

Regards,

Cerebrus.

Feb 23 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gord | last post by:
Hello, I'm dumping a bunch of data from an array into a text box. How can (if it's possible) I change the appearance of certain lines in order to present a better display as I iterate through...
1
by: bala | last post by:
hi there the senario - an A2k application is distributed as a mdb to various users. they are not packaged. rich textbox is being used in one form. requirement - in some of the user's machine...
3
by: Nick J | last post by:
Hi, I have seen exampled were if value is > x then change font/colour/etc. How would I go about doing the same except I would like it so that it changes if there is ANYTHING in the text box. ...
3
by: hermawih | last post by:
Hi , can anyone help me , please . In Ms Rich textbox control , It is easy to insert object than to insert picture . I want to insert picture in my Ms rtf activeX control but Ms Access does...
7
by: Richard Bond | last post by:
Hi Is there anyway to change the characterset/codepage of a specific textbox on a winform. I have read in a "chinese traditional big5" file into memory using a streamreader with the...
3
by: Brad Rogers | last post by:
All, Being immersed in vb.net and trying CSharp after almost a year I forgot the differences. I like vb fixing the uppercase/lowercase names and seeming to be more flexible to code entry. ...
4
by: Neil | last post by:
Just found out that the Microsoft Rich Textbox does not support full text justification, since it's based on Version 1.0 of the RichEdit Window Class, and full text justification is only available...
16
by: Neil | last post by:
I posted a few days ago that it seems to me that the Access 2007 rich text feature does not support: a) full text justification; b) programmatic manipulation. I was hoping that someone might...
5
by: BarryM | last post by:
could somebody please tell me how to search a rich textbox for a particular word and then highlight that word in the rich textbox ; ; on the form theres are textbox called txtsearch, a button...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.