Getting the page height from a WinForms WebBrowser control

筅森魡賤 提交于 2019-11-28 03:42:44

问题


I've been trying for the last few days to get the height of a web page from the Document property of a WebBrowser control.

Here's my latest attempt.

HtmlElementCollection children = webBrowser.Document.All;
int maxOffset = 0;


foreach (HtmlElement child in children) {
    int bottom = 0;
    bottom = child.OffsetRectangle.Bottom;
    if (bottom > maxOffset) {
        maxOffset = bottom;
        pageHeight = maxOffset;
    }
}

I've tried to work out the max height of the page by finding the offset bottom of the lowest element in the page.

The problem is this over shoots the actual length of the page by about 500px in most cases.

Anyone got any ideas? I can't believe how hard it is just to get the height of a page!


回答1:


This worked for me:

webBrowser.Document.Body.ScrollRectangle.Height



回答2:


Find the BODY tag and get the OffsetRectangle.Bottom of that element. This will give you the height of the page.



来源:https://stackoverflow.com/questions/785737/getting-the-page-height-from-a-winforms-webbrowser-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!