从WinForms WebBrowser控件获取页面高度 [英] Getting the page height from a WinForms WebBrowser control

查看:48
本文介绍了从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

这篇关于从WinForms WebBrowser控件获取页面高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆