我如何在.NET HTML转换为RTF(富文本),而无需交纳一个组成部分?转换为、组成部分、文本、如何在

2023-09-02 11:45:48 作者:花朶在沉。

有没有免费的第三方或.NET类,将HTML转换为RTF(在富文本使用功能的Windows窗体控件)?

Is there a free third-party or .NET class that will convert HTML to RTF (for use in a rich-text enabled Windows Forms control)?

自由的要求来自于事实,我只是工作的一个原型,并可以直接加载BrowserControl,只是呈现的HTML,如果需要的话(哪怕是慢),而且开发前preSS是将要推出自己的这种控制很快十岁上下。

The "free" requirement comes from the fact that I'm only working on a prototype and can just load the BrowserControl and just render HTML if need be (even if it is slow) and that Developer Express is going to be releasing their own such control soon-ish.

我不想学手工编写RTF,我已经知道了HTML,所以我想这是可以快速得到一些显而易见的code出了门的最快捷方式。

I don't want to learn to write RTF by hand, and I already know HTML, so I figure this is the quickest way to get some demonstrable code out the door quickly.

推荐答案

其实,有一个简单的和免费解决方案:使用浏览器,确定这是我使用的伎俩:

Actually there is a simple and free solution: use your browser, ok this is the trick I used:

var webBrowser = new WebBrowser();
webBrowser.CreateControl(); // only if needed
webBrowser.DocumentText = *yourhtmlstring*;
while (_webBrowser.DocumentText != *yourhtmlstring*)
    Application.DoEvents();
webBrowser.Document.ExecCommand("SelectAll", false, null);
webBrowser.Document.ExecCommand("Copy", false, null);
*yourRichTextControl*.Paste(); 

这可能是比其他方法要慢,但至少它是免费的,作品!

This could be slower than other methods but at least it's free and works!