When loading a rtf file into a Windows Forms RichTextBox it loses the background colour of table cells. If we use a WPF RichTextBox and load the same file everything is formatted as it should.
Am I missing something when I load the file into the 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 have also tried using
richTextBox1.Rtf = File.ReadAllText(fDialog.FileName);
and
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 the screen shot from both versions :
Thanks in advance for any help.
Steve.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…