Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Gecko WebBrowser控件中注入CSS_C#_Css_Gecko - Fatal编程技术网

C# 如何在Gecko WebBrowser控件中注入CSS

C# 如何在Gecko WebBrowser控件中注入CSS,c#,css,gecko,C#,Css,Gecko,这适用于web浏览器控件,但不能应用于gecko IHTMLDocument2 doc = (webBrowser1.Document.DomDocument) as IHTMLDocument2; IHTMLStyleSheet ss = doc.createStyleSheet("", 0); ss.cssText = @".navSub_top, .navSub_middle, .navSub_bottom { display: none; };"; 你能帮帮我吗 您可以使用以下代码获取

这适用于web浏览器控件,但不能应用于gecko

IHTMLDocument2 doc = (webBrowser1.Document.DomDocument) as IHTMLDocument2;
IHTMLStyleSheet ss = doc.createStyleSheet("", 0);
ss.cssText = @".navSub_top, .navSub_middle, .navSub_bottom { display: none; };";

你能帮帮我吗

您可以使用以下代码获取GeckoStyleSheet:

var stylesheet = browser.Document.StyleSheets.First(x => x.Href.EndsWith("SomeStylesheetName.css"));
现在,有了样式表,您可以访问CssRules集合并添加新规则:

stylesheet.CssRules.Add(@".navSub_top, .navSub_middle, .navSub_bottom { display: none; };");
或通过访问现有规则并使用例如StyleCssText来编辑现有规则


您可以使用以下代码获得壁虎化石:

var stylesheet = browser.Document.StyleSheets.First(x => x.Href.EndsWith("SomeStylesheetName.css"));
现在,有了样式表,您可以访问CssRules集合并添加新规则:

stylesheet.CssRules.Add(@".navSub_top, .navSub_middle, .navSub_bottom { display: none; };");
或通过访问现有规则并使用例如StyleCssText来编辑现有规则