views:

746

answers:

4

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.

+4  A: 

For managed HTML renderer see HtmlRenderer at codeproject.com

altso
Now that looks sexy, going to give it a try.
Michael Stum
A: 

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/

Simon
I don't think that those will do be any good - to my understanding, they create HTML from a template. I am looking for something that renders HTML on screen, aka. a Browser.
Michael Stum
A: 

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

Michael Stum
A: 

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.

ChrisW