合并两个rtf文件

rtf文件类似于xml文件,是一种文本化、格式化的结构性文件,微软定义了很多标记,构成很多版本,也可以自定义标记(那就只能自己解析了,因此意义不大,别的rtf阅读器打不开的),主要的标记就是{\rtf1.....},由一对花括号括起来,紧接着是rtf+版本号,版本号多少都可以。里面的内容是递归式的,会有许多标记,不去细究,知道这些就够了。

看代码:

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;
        }
//调用方式  richTextBox3.Rtf=HeBingRTF(rtfFile1,rtfFile2);

 但是以上的代码会有问题,颜色表不能自动适应,还是用剪切板解决吧

            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();
原文地址:https://www.cnblogs.com/eyye/p/2738850.html