Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

c# - Getting the page height from a WinForms WebBrowser control

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This worked for me:

webBrowser.Document.Body.ScrollRectangle.Height

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...