Re: Frustrations with RTF format.

Tech-Archive recommends: Fix windows errors by optimizing your registry



I am not sure what you are trying to accomplish here. If you want to use an
RTF control to get all your formatting and stuff then why are you trying to
display that text in a plain text box and expect it to look anything like
the RTF formatted document. Open a MS Word doc in Notepad and see what you
get. If you want to get the data out of Word into a plain text file you need
to do a Save As and select a different file type that invariably takes a
different code path and saves the text as raw ASCII. Doing this even brings
up a dialog box that allows you to pick the formatting that you want to use
for that plain text document. It lets you sent the encoding to use, the
ability to insert line breaks, to end lines with CR\LF - LF\CR - CR Only -
LF Only, and even to do character substitution.

I would suggest that things are not as 'standard' as you had hoped but there
is no doubt that RTF in and of itself is a standard and so is ASCII text.
You can't compare the two as apples-to-apples and clearly converting between
them is going to take some wheel inventing to get done what you want.


"AWesner" <AWesner@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:AA995236-9766-459E-9FC5-B7FF9CAC2B01@xxxxxxxxxxxxxxxx
For readability sake I'm going to first state that:
LF = Line Feed CHR(10)
CR = Carriage Return CHR(13)

Since Rich Text Format is a standard formalized by Microsoft Corporation I
get to ask them why they decided that RTF format needed to start writing
LF
instead of the CRLF that you see in implemented in non formatted text such
as
seen via notepad. Nor can I find any history on why the decision was made.
Was it forgotten and just left behind because RTF knew the formatting and
that was all that mattered? I only find on Google many different people in
many different coding languages trying to deal with the differences. Even
on
Microsoft's site that is all I find.

My main point of interest here is why a Richtextbox.text property would
yield a string that doesn't fit the plain text standard which ends with
CRLF?
And even if this .text property did not provide a way to do that why can't
I
find an inherent method that will do this type of conversion? It's not a
string conversion after all. They are both clearly strings but with a
different choice of line feed. Do I have to write a conversion algorithm
myself? If so, that's fine. But from all my Google searching I know that I'm
not the first to address this issue.

Why would I want to use an old standard? Well, without a CR your plain
text
files look pretty ugly and depending on which programs are trying to read
from these files, they may become dysfunctional after being written from a
Richtextbox if they are expecting CRs. I simply do not want to change the
original format of the files that go through my program and I think that's
a
reasonable request ?

Using RTF is unavoidable. I need its formatting capabilities to present to
the user the plain text files with highlighted areas of importance.
However
when I stuff the contents back into a plain text file, I would like the
formatting to be converted back to plain text and what I mean by that is
the
implementation of CRLF instead of just LF.

I am aware of the Richtextbox.Savefile method. However this cannot be used
to set the value to another data structure within memory and has to use
the
FSO to store and retrieve the data. This is undesirable for the solution I
need. But this is the only way I currently know of that will do the proper
type of conversion for you.

If somebody can tell me an easy way to accomplish this in VB.net

1: Create a form.
2: Place 1 Pushbutton, 1 Richtextbox and 1 Textbox.
3: Change the properties of the textbox to Multiline = True and WordWrap =
False.
4: Make the boxes big enough to show a few lines of text.

Enter the code for the Click event of Pushbutton: Textbox.text =
Richtextbox.text

Now go run the program and enter in a few lines of data into the RTB and
hit
the pushbutton. Watch as the textbox fails to write new lines properly
because there is no CR.

How do I efficiently get around this without reinventing the wheel?



.


Quantcast