惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
D
Docker
Stack Overflow Blog
Stack Overflow Blog
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
H
Help Net Security
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
L
LangChain Blog
MongoDB | Blog
MongoDB | Blog
腾讯CDC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
SegmentFault 最新的问题
博客园 - 司徒正美
C
Check Point Blog
B
Blog
Y
Y Combinator Blog
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
F
Fortinet All Blogs
美团技术团队
D
DataBreaches.Net

博客园 - eyye的眼睛

又到清明节 sql中去除重复的项 戒烟吧 李开复:如何设计你的2015年度计划 网易邮箱已经忘记了客户 用程序集编写clr表值函数:把正则表达式引入数据库中 从天气网提取气象预报数据 sql 几点记录 sql 重复数据只保留一条 (转)android-sdk_r20.0.3-windows无法正常更新 RichTextBox的拖放功能DragDrop 杀掉叽哩瓜叽(jlguaji.exe)的两种方法 股票数据(转) word转化为图片(2) 如何将格式文本转化为图片 SQL Server 的事务处理的两种格式 sql IN语句如何优化?(转) 向EXCEL批量导出数据(转) 禅语
合并两个rtf文件
eyye的眼睛 · 2012-10-25 · via 博客园 - eyye的眼睛

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();