防止 WPF WebBrowser 显示内容的滚动条

发布于 2024-08-15 04:19:25 字数 264 浏览 7 评论 0原文

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

基本上,我如何强制(或以其他方式实现强制)WebBrowser 扩大尺寸,以便显示所有内容而不需要滚动条?

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风铃鹿 2024-08-22 04:19:25

我想您可以通过其 Document 属性获取网络浏览器组件内容的宽度和高度,该属性应该是 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;
}

希望这有帮助,问候

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:

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

白况 2024-08-22 04:19:25

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

这是我的解决方案:

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

问候,

阿萨夫

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.

Here is my solution:

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

Regards,

Assaf

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文