在WinForms应用程序中呈现HTML的最佳方法? [英] Best Way to Render HTML in WinForms application?

查看:133
本文介绍了在WinForms应用程序中呈现HTML的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WinForms应用程序,运行在.net 3.5上。这个应用程序会随时生成HTML,其中包括完整的文档,以及inline-CSS-Stylesheet(在head元素中)。



我使用WebBrowser控件并将browser.DocumentText设置为我生成的HTML,但似乎并没有在body元素上正确应用样式(我在CSS中将背景颜色设置为#000000,但背景仍然是白色)。



我想知道a)是否有一些替代方法可以在C#中呈现相对简单的HTML(即完全托管的HTML呈现器)或b)使用WebBrowser呈现HTML的最佳方式是什么控制,包括正确处理inline-css和不在硬盘上使用临时文件。



编辑:问题是一个单独的问题。我把我的实际CSS放在一个CDATA块中,这似乎导致它不能正确应用。现在已经解决了,但问题本身仍然存在。 解决方案

使用内置的WebBrowser。来自其他答案的HtmlRenderer很棒,但呈现图像。


I have a WinForms application, running on .net 3.5. This Application generates HTML on the fly, which includes the complete document, and also an inline-CSS-Stylesheet (inside the head element).

I am using the WebBrowser control and setting browser.DocumentText to my generated HTML, but that does not seem to properly apply styles on the body element (I've set background-color to #000000 in the CSS, but the background is still white).

I wonder if a) there are some alternatives to render relatively simple HTML in C# (i.e. a completely managed HTML renderer) or b) what would be the best way to render HTML using the WebBrowser control, including correct handling of inline-css and without using a temporary file on the hard drive.

Edit: The CSS-not-applying issue was a separate problem. I've put my actual CSS in a CDATA block, which seems to cause it not to apply correctly. That is now fixed, but the question itself still stands.

解决方案

Stayed with the built-in WebBrowser. The HtmlRenderer from the other answer is great, but renders an image.

这篇关于在WinForms应用程序中呈现HTML的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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