如何使用选项卡将richtextbox文档保存在文本文件中 [英] How do I save richtextbox document in a text file with tabs

查看:128
本文介绍了如何使用选项卡将richtextbox文档保存在文本文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个richtextbox,我想把它的文档保存到.txt文件中。我使用此代码保存内容

Hi everybody,

I have a richtextbox and I want to save its document into a .txt file. I used this code to save content

TextRange t = new TextRange(this.MyRichTextBox.Document.ContentStart, this.MyRichtextbox.document.contentend);
FileStream fs = new FileStream (MyPath, FileMode.Open, FileAccess.Write);
t.Save(fs, DataFormats.Text)
Fs.close()





这个加载





And this to load

TextRange t = new TextRange(this.MyRichTextBox.Document.ContentStart, this.MyRichtextbox.document.contentend);
FileStream fs = new FileStream (MyPath, FileMode.Open, FileAccess.Read);
t.Load(fs, DataFormats.Text)
Fs.close()





问题在于表格未正确保存。如果我想作为文件类型,文本,我该怎么办?我决定这是因为rtf有格式属性,我不希望我的程序在richtextbox中使用...



谢谢!!



The problem is that tabulations are not saved correctly. What should I do if I want to mantain, as filetype, Text? I decided it because rtf has formatting property which I do not want my program to use inside the richtextbox...

Thanks!!

推荐答案

您永远无法使用制表符,空格和文本文件的类似内容可靠地模仿RTF(或任何其他或更高级的)格式。为什么这样做呢?这只是个坏主意。您可以使用相同的RTF,或者说HTML。几乎所有平台上的每个人都可以查看这两种格式。另一种可能性是PDF。



或者,将文本表示更改为非常简单的东西,纯文本可以做的事情,没有不适合文本文件的列或其他格式。



-SA
You will never can reliably mimic RTF (or any other as or more advanced) formatting with tabs, blank spaces and similar stuff of a text file. Why doing that at all? This is just a bad idea. You can use the same RTF or, say, HTML. These two formats can be viewed by everyone, on nearly all platforms. Another possibility is PDF.

Alternatively, change the textual representation to something really simple, something which a plain text can do, without columns or other formatting inappropriate to text files.

—SA






我成功地解决了我的问题:

由于rtf格式优先于richtextbox格式,我无法使用它(至少我已经注意到了)。

我用 XamlPackage 解决了我的问题,这让我没有任何问题,而xaml给了我奇怪的问题



所以解决方案我已经使用了





我使用此代码保存内容



Hi,

I succeded in solving my problem:
As rtf formatting is prior over the richtextbox one, I couldn't use it (at least as I could have noticed).
I solved my problem using XamlPackage which gave me no problems at all while xaml gave me strange problems with

So the solution I've used is


I used this code to save content

TextRange t = new TextRange(this.MyRichTextBox.Document.ContentStart, this.MyRichtextbox.document.contentend);
FileStream fs = new FileStream (MyPath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
t.Save(fs, DataFormats.XamlPackage)
Fs.close()



 

这就是加载

 


 
And this to load
 

TextRange t = new TextRange(this.MyRichTextBox.Document.ContentStart, this.MyRichtextbox.document.contentend);
FileStream fs = new FileStream (MyPath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
t.Load(fs, DataFormats.XamlPackage)
Fs.close()


这篇关于如何使用选项卡将richtextbox文档保存在文本文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆