Kev*_*ose 10 c# wpf scrollbar webbrowser-control
我正在使用WPF WebBrowser组件来显示一些非常简单的HTML内容.但是,由于我事先并不知道内容大小,因此当我加载某些数据集时,我正在获取控件上的滚动条.
基本上,我如何强制(或以其他方式影响相当于强制)WebBrowser扩展大小,以便显示所有内容而不需要滚动条?
我想你可以通过它的Document属性得到webbrowser组件内容的宽度和高度,该属性应该是mshtml.HTMLDocument类型.我相信你应该能够使用body或documentElement属性来获得所需的大小; 像这样:
mshtml.HTMLDocument htmlDoc = webBrowser.Document as mshtml.HTMLDocument;
if (htmlDoc != null && htmlDoc.body != null)
{
mshtml.IHTMLElement2 body = (mshtml.IHTMLElement2)htmlDoc.body;
webBrowser.Width = body.scrollWidth;
webBrowser.Height = body.scrollHeight;
}
Run Code Online (Sandbox Code Playgroud)
希望这有帮助,问候
小智 6
以前的解决方案的问题是它更改了控件大小,并且由于浏览器控件无法被剪切并且始终位于其他WPF元素之上,因此它可能会覆盖其他元素.
这是我的解决方案:
Dim body = CType(WebBrowserControl.Document, mshtml.HTMLDocumentClass)
body.documentElement.style.overflow = "hidden"
Run Code Online (Sandbox Code Playgroud)
问候,
阿萨夫
| 归档时间: |
|
| 查看次数: |
8122 次 |
| 最近记录: |