Currently trying to inject CSS in a WebBrowser control using IHTMLStyleSheet
How to inject CSS in WebBrowser control?
I read this and I think it helped a bit but what's there doesn't seem to work for me.
IHTMLDocument2 doc = (webBrowser1.Document.DomDocument) as IHTMLDocument2;
IHTMLStyleSheet ss = doc.createStyleSheet("", 0);
ss.addRule("body", "background-color:#000");
ss.cssText = @"h1 { color: blue; }";
This is what I currently have, do I need to add it to the control after this or what am I doing wrong here?
EDIT: Got it working here's what I did
CurrentDocument = (mshtml.HTMLDocument)webBrowser1.Document.DomDocument;
styleSheet = CurrentDocument.createStyleSheet("", 0);
StreamReader streamReader = new StreamReader(@"test.css"); //test.css is Stylesheet file
string text = streamReader.ReadToEnd();
streamReader.Close();
styleSheet.cssText = text;