views:

780

answers:

2

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  A: 

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

Rob
That doesn't work for me. It always gives me the size of the browser control, not of the contents
nikie
+1  A: 

This worked for me:

webBrowser.Document.Body.ScrollRectangle.Height
dr steve