本文介绍了如何使用选项卡将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!!
推荐答案
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文档保存在文本文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!