【问题标题】:Extracting raw RTF from a RichTextBox从 RichTextBox 中提取原始 RTF
【发布时间】:2013-02-09 03:12:13
【问题描述】:

一定有比我现在做的更好的方法来做到这一点。

我正在尝试从 WPF RichTextBox 中提取原始 RTF。好吧,实际上我正在尝试将一堆自定义类转换为 RTF 字符串,但我使用 RichTextBox 来执行此操作,因为我不想编写自己的 RTF 库。

我正在使用的方法(从最初看到的here修改并用于提取XML here)如下:

RTB.Selection.Save(memstream, DataFormats.Rtf);
memstream.Seek(0, SeekOrigin.Begin);
var sr = new StreamReader(memstream);
var myText = sr.ReadToEnd();

这可行,但看起来非常笨拙。而且我担心对大量文本的性能影响。有没有更好的办法? (出于这个问题的目的,我们假设我不能使用 WinForms RichTextBox。)

【问题讨论】:

    标签: c# wpf wpf-controls rtf


    【解决方案1】:

    使用this问题。

    string mpic = @"{\pict\pngblip\picw" + 
        img.Width.ToString() + @"\pich" + img.Height.ToString() +
        @"\picwgoal" + width.ToString() + @"\pichgoal" + height.ToString() + 
        @"\bin " + str + "}"
    

    【讨论】:

      猜你喜欢
      • 2014-10-09
      • 2010-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多