[英]Extracting raw RTF from a RichTextBox
There's got to be a better way to do this than what I'm doing. 有比我正在做的更好的方法。
I'm trying to extract the raw RTF from a WPF RichTextBox. 我正在尝试从WPF RichTextBox中提取原始RTF。 Well, really I'm trying to take a bunch of my custom classes and turn it into an RTF string, but I'm using a RichTextBox to do it because I don't particularly want to write my own RTF library.
好吧,确实,我想尝试一堆自定义类并将其转换为RTF字符串,但是我使用RichTextBox来完成此操作,因为我特别不想编写自己的RTF库。
The method I'm using (modified from something first seen here and used to extract XML here ) is as follows: 我使用的方法(从东西第一次看到修改在这里和用于提取XML 这里 )如下:
RTB.Selection.Save(memstream, DataFormats.Rtf);
memstream.Seek(0, SeekOrigin.Begin);
var sr = new StreamReader(memstream);
var myText = sr.ReadToEnd();
This works, but seems ridiculously clumsy. 这行得通,但是看起来很笨拙。 And I'm worried about the performance implications on large amounts of text.
而且我担心大量文本对性能的影响。 Is there a better way?
有没有更好的办法? (For the purpose of this question, let's assume that I can't use the WinForms RichTextBox.)
(出于这个问题的目的,让我们假设我不能使用WinForms RichTextBox。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.