获取RTF从RichTextBox中 [英] Get RTF from RichTextBox

查看:153
本文介绍了获取RTF从RichTextBox中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何得到一个RichTextBox的RTF文本?我试图让这个样子,但属性不存在。

How do I get the text in RTF of a RichTextBox? I'm trying to get like this, but the property does not exists.

RichTextBox rtb = new RichTextBox();
string s = rtb.Rtf;

这不工作:•

推荐答案

要获取由用户创建的实际XAML RichTextBox的内部:

To get the actual XAML created by the user inside of the RichTextBox:

   TextRange tr = new TextRange(myRichTextBox.Document.ContentStart,
                                myRichTextBox.Document.ContentEnd);
   MemoryStream ms = new MemoryStream();
   tr.Save(ms, DataFormats.Xaml);
   string xamlText = ASCIIEncoding.Default.GetString(ms.ToArray());

编辑:我没有code在我的面前进行测试,但对的TextRange 类型有一个保存实例(流)的方法,需要一个 DataFormats 参数,可以是 DataFormats.Rtf

I don't have code in front of me to test, but an instance of the TextRange type has a Save (to stream) method that takes a DataFormats parameter, which can be DataFormats.Rtf

这篇关于获取RTF从RichTextBox中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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