All, I write a log file to a .rtf file which has formatting underlining, bold etc. I have saved this file and want to read it back into the RichTextBox
at a later time persisting its formatting. I have tried the following
tmpRichTextBox.LoadFile(@"F:\Path\File.rtf", RichTextBoxStreamType.RichText);
It loads the file but there is none of my original formatting. If I load the .rtf into word, the formatting shows up. How do I read the .rtf back into the RichTextBox
including its formatting?
Thanks for your time.
Did you Check NRTFTree
.
Its an awesome library for RTF management!
Edited:
It's possible that you are losing the formating later in code. There are certain operations that may cause the loss of the formating. For example,
richTextBox.Font = newFont;
I had this problem, but luckily I found a way around it. Here's the code that will let you change the font without losing the formating:
richTextBox.SelectAll();
richTextBox.SelectionFont = newFont;
string rtf = richTextBox.SelectedRtf;
richTextBox.Font = newFont;
richTextBox.Rtf = rtf;
If you can save your log file to html format you can read this file with WebBrowser Control. Like this:
private void button1_Click(object sender, EventArgs e)
{
string fileName = Path.Combine(Environment.CurrentDirectory, "log1.htm");
webBrowser1.DocumentText = File.ReadAllText(fileName);
}
This works perfectrly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With