vexe
vexe

Reputation: 5615

How To Read an .rtf via a StreamReader Ignoring the .rtf file formatting ? (Not Maintaining it)

I have a StreamReader reading from a .txt, .rtf and .docx files. I store what is read in a string variable, then I print this variable to a RichTextBox the problem is that my RichTextBox BackColor is Black and the ForeColor is Green, so if the text color in the .rtf file is black, it won't be visible in the TextBox, not to mention that it won't use the Font that I specified in my TextBox !

Maybe I could just use a normal TextBox, not a RichTextBox, but that way I won't be able to Color the text in the TextBox...

How Can I fix That ?

Upvotes: 1

Views: 2779

Answers (1)

Jim Mischel
Jim Mischel

Reputation: 134125

One possibility would be to have a second, invisible, RichTextBox on the form. Read the RTF from the StreamReader, store it in the hidden text box, then read the text from the hidden text box and write it to the visible one. Something like:

string rtfText = File.ReadAllText(filename);
hiddenTextBox.Rtf = rtfText;
visibleTextBox.Text = hiddenTextBox.Text;

Not exactly elegant, but it handles the nasty work of stripping the formatting for you.

Upvotes: 1

Related Questions