当前正在尝试使用 IHTMLStyleSheet 在 WebBrowser 控件中注入(inject) CSS
How to inject CSS in WebBrowser control?
我读了这篇文章,我认为它有点帮助,但其中的内容似乎对我不起作用。
IHTMLDocument2 doc = (webBrowser1.Document.DomDocument) as IHTMLDocument2;
IHTMLStyleSheet ss = doc.createStyleSheet("", 0);
ss.addRule("body", "background-color:#000");
ss.cssText = @"h1 { color: blue; }";
这是我目前拥有的,我是否需要在此之后将其添加到控件中,或者我在这里做错了什么?
编辑: 让它工作在这里,这就是我所做的
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;
最佳答案
我做了什么来让它工作
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;
关于c# - 在 WebBrowser 控件中注入(inject) CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48576595/