Question

I have Some Text files that my program will parse through looking for specific lines as requested by the user to be displayed into a RichTextBox during runtime. There are certain comments in each line that I would like displayed in Red not the normal ForeColor, only one line "Scripture" will ever be displayed in the RichTextBox at any given time. Is there a way to add formatting in a Text File that when displaying a specific line into a RichTextBox it will display the comment you want with color?

ie... I have a Bible Scripture:

Then Jesus turned, and saw them following, and saith unto them, \What seek ye?\ They said unto him, Rabbi, (which is to say, being interpreted, Master,) where dwellest thou?

I want the words "What seek ye?" to be in red when it is displayed in the RichTextBox. The problem of course is that the program does not know which comments need to be displayed in red and the user will not have any control over that, so it needs to be something that can be handled from the File being read in.

The Format of the Text Files are basically:

(John 2:2) And both Jesus was called, and his disciples, to the marriage.

(John 2:3) And when they wanted wine, the mother of Jesus saith unto him, They have no wine.

(John 2:4) Jesus saith unto her, Woman, what have I to do with thee? mine hour is not yet come.

(John 2:5) His mother saith unto the servants, Whatsoever he saith unto you, do it.

Does anyone have any Ideas how I can get this accomplished? In the above Text example if the 3rd line (John 2:4) were to be displayed into the RichTextBox I would want the comments "Woman, what have I to do with thee? mine hour is not yet come." to be displayed in Red.

basically Im trying to create a random scripture generator to show a random scripture when the program runs and I'd like to give it Red Letter Formatting for the words of Jesus.

Was it helpful?

Solution

Here is an example of how the RTF property of a richtextbox will look for your text:

{\rtf1{\fonttbl{\f0\fnil\fcharset0 Tahoma;}}
{\colortbl ;\red255\green0\blue0;}
\f0\fs24 Then Jesus turned, and saw them following, and saith unto them, \cf1 What seek ye?\cf0  They said unto him, Rabbi, (which is to say, being interpreted, Master,) where dwellest thou?\par
}

Note the color defined in the color table (colortbl) which is red at index 1. I has the tag \cf1. Default \cf0 is black.

So use the same header I gave (you can change the font).

You can use a regular expression to replace \...\ with \cf1 ...\cf0. As an alternative, you can use {\cf1 ...}

Then assign the result (whole rtf) to the rtf property of a richtextbox. If you need help with any of this let me know.

By the way, it would be better if you can tag the red letters with some different tags, for example <Red>...<red> or <R>...<r> instead of \...\ to avoid problems.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top