Best Way to Render HTML in WinForms application? [closed]

痴心易碎 提交于 2019-12-20 09:02:04

问题


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.


回答1:


For managed HTML renderer see HtmlRenderer on GitHub.




回答2:


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




回答3:


Your could look into using a view engine. Most view engines can work in a stand-alone api manner

for example NHaml and nvelocity both can be used stand alone

http://code.google.com/p/nhaml/

http://www.castleproject.org/others/nvelocity/index.html

And i assume Spark can be as well

http://dev.dejardin.org/




回答4:


I have developed what you were asking for: a "completely managed HTML renderer", which will "render relatively simple HTML in C#". It supports a subset of CSS, which you can "specify in a inline CSS stylesheet (inside the head element)".

For details, see the ModelText HTML control.



来源:https://stackoverflow.com/questions/1218325/best-way-to-render-html-in-winforms-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!