1

I am using the System.Windows.Controls.WebBrowser control, and I need to get the height of the rendered html document. (Not the height of the control, the height of the content)

The only height value I've found is WebBrowser.Document.body.offsetheight. However, this is the same value as the control's height.

I know the height of the page must be stored someplace since the scroll bar knows the value.

Everything I find in my searching has been about the Windows.Forms.WebBrowser.

Dan Vogel
  • 3,858
  • 7
  • 41
  • 57

1 Answers1

1

Add COM reference "Microsoft HTML Object Library" to the project, and use this:

mshtml.HTMLDocument doc = (mshtml.HTMLDocument)this.Browser1.Document;
mshtml.IHTMLElement2 elem = (mshtml.IHTMLElement2)doc.activeElement;
int height = elem.scrollHeight;
Dan Vogel
  • 3,858
  • 7
  • 41
  • 57
  • 1
    It's possible to use late-binding via `dynamic` for this, without the overhead of MSHTML PIA: `int height = ((dynamic)this.Browser1.Document).activeElement.scrollHeight`. You may also want to implement [WebBrowser Feature Control](http://stackoverflow.com/a/18802626/1768303) for consistent measurement results. – noseratio Sep 20 '13 at 03:59
  • @Dan - I have voted to delete my answer below since it doesn't actually answer your question. – Brian Sep 21 '13 at 17:29