views:

126

answers:

2

Is there any way to detect the contents height/width in the WebBrowser control? I'd like to save the contents to an image but only at the size of the actual contents.

Thank you in advance.

+2  A: 

I believe you can get it from the following property:

myWebBrowser.Document.ScrollRectangle.Size;

Being a System.Drawing.Size object.

Aren
That's not it. That defaults to 250x250.
Nissan Fan
Thanks for the idea, I used to to figure out it was available here: browser.Document.Body.ScrollRectangle using width/height.
Nissan Fan
Yeah, I knew the information was available in there somewhere, sorry for the inaccuracy, I'll edit my above post for people searching for similar solutions.
Aren
A: 

The document recalculate the layout each time the size of the browser window changes, so it does not really have a fixed size.

You can using a Golden section search to find the minimal window size large enough to contain the document, but it is a CPU-intensive task.

Sheng Jiang 蒋晟