c#如何保存richtextbox的rtf格式

C# code
this.rtbText.Rtf = @"{\rtf1\ansi\ansicpg936\deff0\deflang1033\deflangfe2052"
+ @"{\fonttbl{\f0\fmodern\fprq6\fcharset134 \ 'cb\ 'ce\ 'cc\ 'e5;}{\f1\fnil\fcharset134 \ 'cb\ 'ce\ 'cc\ 'e5;}}"
+ @"{\colortbl;\red0\green0\blue0;}"
+ @"\viewkind4\uc1\pard\cf1\lang2052\f0\cf1 }";
打开文件,如果是文本文件,用PlainText类型打开,其他的都用默认方法打开,也就是RFT格式的方法
if ((System.IO.Path.GetExtension(FileName)).ToLower() == ".txt")
richTextBox.LoadFile(FileName, RichTextBoxStreamType.PlainText);
else
richTextBox.LoadFile(FileName);

保存
if ((System.IO.Path.GetExtension(FileName)).ToLower() == ".txt")
richTextBox.SaveFile(FileName, RichTextBoxStreamType.PlainText);
else
richTextBox.SaveFile(FileName);

posted on 2017-11-22 14:31  王浩祥  阅读(3074)  评论(0编辑  收藏  举报

导航