我正在Windows应用程序中使用Web浏览器控件。我想更改滚动条的外观。为此,我找到了下面给出的代码项目链接。这似乎更麻烦。因此,取而代之的是任何其他方法可以自定义滚动条。我想设计没有向上和向下箭头的滚动条。只是滚动器。我无法用这段代码做到这一点。或者我可以更改默认滚动条的外观和感觉,即颜色宽度等。
您可以使用
IHTMLDocument2.styleSheets
来设置样式表:
IHTMLDocument2 _htmlDocument = webBrowser.Document.DomDocument as IHTMLDocument2;
int length = _htmlDocument.styleSheets.length;
IHTMLStyleSheet styleSheet = _htmlDocument.createStyleSheet(@"", length + 1);
styleSheet.addRule("BODY", "scrollbar-face-color: #FF0000;");
styleSheet.addRule("BODY", "scrollbar-highlight-color: #FF00FF;");
styleSheet.addRule...
或者可以直接在HTML
代码中设置CSS
:
CSS:
<STYLE type="text/css">
<!--
BODY
{
scrollbar-face-color: #FF0000;
scrollbar-highlight-color: #FF00FF;
scrollbar-3dlight-color: #00FF00;
scrollbar-darkshadow-color: #00FFFF;
scrollbar-shadow-color: #0000FF;
scrollbar-arrow-color: #FF00FF;
scrollbar-track-color: #FFFF00;
}
-->
</STYLE>
并在C#
代码集中WebBrowser.DocumentText
属性中:
webBrowser.DocumentText = "<html><head><STYLE type="text/css"><!--BODY{scrollbar-face-color: #FF0000;scrollbar-highlight-color: #FF00FF;scrollbar-3dlight-color: #00FF00;scrollbar-darkshadow-color: #00FFFF;scrollbar-shadow-color: #0000FF;scrollbar-arrow-color: #FF00FF;scrollbar-track-color: #FFFF00;}--></STYLE></head><body>aaaa</body></html>";
请注意:只有在运行 IE 5.5 时才能看到彩色滚动条。