The rtf file is similar to an xml file. It is a structured and formatted file. Microsoft has defined many tags to form many versions and can also customize tags (you can only Parse them yourself, so it doesn't make much sense, and other rtf readers cannot open), the main mark is {\ rtf1 .....}, enclosed by a pair of curly braces, followed by the rtf + version number, which can be any version number. The content in it is recursive, and there will be many tags. It is enough to know this without going into details.
Check the Code:
private string HeBingRTF(string rtfFile1, string rtfFile2) { System.IO.FileStream fs1 = new System.IO.FileStream(rtfFile1,System.IO.FileMode.Opene.Open); System.IO.FileStream fs2 = new System.IO.FileStream(rtfFile2,System.IO.FileMode.Opene.Open);
RichTextBox richTextBox1 = new RichTextBox(); RichTextBox richTextBox2 = new RichTextBox(); richTextBox1.LoadFile(fs1, RichTextBoxStreamType.RichText); richTextBox2.LoadFile(fs2, RichTextBoxStreamType.RichText); fs1.Close(); fs2.Close(); string f1 = richTextBox1.Rtf;
string f2=richTextBox2.Rtf; string pre = @"{\rtf1"; string end = @"}";
return pre + f1 + f2 + end;
}
// Call method richTextBox3.Rtf = HeBingRTF (rtfFile1, rtfFile2 );
However, the above Code may be problematic, and the color table cannot be automatically adapted. You should use a clipboard to solve the problem.
System.Windows.Forms.DataObject data = new System.Windows.Forms.DataObject(); data.SetData(System.Windows.Forms.DataFormats.Rtf, rtf); System.Windows.Forms.Clipboard.SetDataObject(data, true); richtextbox1.Paste();