如何获取 RichTextBox
的 RTF 文本?我正在尝试这样做,但该属性不存在。
RichTextBox rtb = new RichTextBox();
string s = rtb.Rtf;
最佳答案
获取用户在 RichTextBox 内部创建的实际 XAML:
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());
编辑:我面前没有要测试的代码,但是 TextRange
类型的实例有一个 Save
(流)方法,它需要一个DataFormats
参数,可以是DataFormats.Rtf
关于c# - 如何从 RichTextBox 获取 RTF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/601838/