When you load an RTF file into RichTextBox Windows Forms, it loses the background color of the table cells. If we use WPF RichTextBox and load the same file, everything will be formatted as it should.
Am I missing something when uploading a file to Windows Forms RichTextBox?
Windows Forms RichTextBox code snippet:
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog fDialog = new System.Windows.Forms.OpenFileDialog();
fDialog.Filter = "Rich Text Files (*.rtf)|*.rtf";
fDialog.Multiselect = false;
fDialog.RestoreDirectory = true;
if (fDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
if (fDialog.FileName != "")
{
richTextBox1.LoadFile(fDialog.FileName, RichTextBoxStreamType.RichText );
}
}
}
In the above code snippet, I also tried to use
richTextBox1.Rtf = File.ReadAllText(fDialog.FileName);
as well as
richTextBox1.LoadFile(fDialog.FileName);
WPF RichTextBox Code Snippet
private void load_file_Click(object sender, RoutedEventArgs e)
{
System.Windows.Forms.OpenFileDialog fDialog = new System.Windows.Forms.OpenFileDialog();
fDialog.Filter = "Rich Text Files (*.rtf)|*.rtf";
fDialog.Multiselect = false;
fDialog.RestoreDirectory = true;
if (fDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
if (fDialog.FileName != "")
{
FileStream fStream;
fStream = new FileStream(fDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
richtextbox1.SelectAll();
richtextbox1.Selection.Load(fStream, DataFormats.Rtf);
fStream.Close();
}
}
}
Here is a screenshot from both versions: 
Thank you in advance for any help.
Steve.
source
share