How to add a stylesheet into a WinForm WebBrowser in C#?

342 views Asked by At

I am wanting to manipulate a page being loaded in a WebBrowser by adding a stylesheet on the DocumentComplete event. I'd like to do it without using an external file, if possible.

Most of the solutions I've seen involve deprecated methods or libraries such as mshtml. The MSDN says that the accepted method is to use HtmlElement myelement = mywebbrowser.Document.CreateElement( "style"), but nothing else. Manipulation of such seems to be problematic - things like trying to set InnerHtml throws an error at runtime (ie, System.NotSupportedException: Property is not supported on this type of HtmlElement).

Given all that, what is the best/proper way to add a big chunk of CSS to a page loaded in a WebBrowser?

0

There are 0 answers