从WinForms WebBrowser控件获取页面高度

问题描述:

最近几天,我一直在尝试从 WebBrowser 控件的Document属性获取网页的高度.

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.

这是我的最新尝试.

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.

问题在于,在大多数情况下,这会使页面的实际长度超出大约500像素.

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!

这对我有用:

webBrowser.Document.Body.ScrollRectangle.Height