Alex Rivera | Logout

Best Way to Render HTML in WinForms application?

Asked 2009-08-02T07:08:54.067
16

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.

Edit
Report

2 Answers

4

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

answered 2010-01-01T23:29:57.430
0

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/

answered 2009-08-02T08:26:14.347

Your Answer