使用WPF WebBrowser显示内容来阻止滚动条

[英]Prevent scrollbars with WPF WebBrowser displaying content


I'm using the WPF WebBrowser component to display some very simple HTML content. However, since I don't know the content size in advance, I'm currently getting scrollbars on the control when I load certain datasets.

我正在使用WPF WebBrowser组件来显示一些非常简单的HTML内容。但是,由于我事先并不知道内容大小,因此当我加载某些数据集时,我正在获取控件上的滚动条。

Basically, how can I force (or otherwise effect the equivalent of forcing) the WebBrowser to expand in size so that all content is displayed without the need for scrollbars?

基本上,我如何强制(或以其他方式影响相当于强制)WebBrowser扩展大小,以便显示所有内容而不需要滚动条?

2 个解决方案

#1


7  

I guess you can get width and height of the webbrowser component content through its Document property which should be of mshtml.HTMLDocument type. I believe you should be able to use body or documentElement properties to get needed sizes; smth like this:

我猜你可以通过它的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;
}

hope this helps, regards

希望这会有所帮助,问候

#2


6  

The problem with previous solution is that it changes the control size and since the browser control cannot be clipped and is always on top of other WPF elements, it may cover the other elements.

以前的解决方案的问题是它更改了控件大小,并且由于浏览器控件无法被剪切并且始终位于其他WPF元素之上,因此它可能会覆盖其他元素。

Here is my solution:

这是我的解决方案:

Dim body = CType(WebBrowserControl.Document, mshtml.HTMLDocumentClass)
body.documentElement.style.overflow = "hidden"

Regards,

问候,

Assaf

阿萨夫

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2009/12/16/13d0808ecdafa2265e69b0cd4d3b107b.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告