I’ve got a web browser control that needs to have a specific height set. If the user has a small amount of text, I want the web browser to be short. If the user types alot of text, then I need the web browser to be alot taller.
How can I find the height of the rendered text from the WebBrowser?
I saw this Getting the page height from a C# web browser control but thought there was a better way.
Update
I’m setting the text of the browser with:
webBrowser1.DocumentText = value;
After I set this value, I can check the webBrowser1.Document.Body and its null. I can also get all children of the document and none are returned.
Am I setting the correct property?
Something I’ve noticed with webBrowser.DocumentText is that you cannot necessarily “get” it’s value immediately after setting it it.
This will not produce predictable results because the webbrowser control may not have finished rendering the text yet. If it is run repeatedly, and “Some Text” is a variable, you will see that “labelHtml” quickly becomes out of sync with what is in your browser control. (The more complex “Some Text” is the longer it takes to render naturally.)
If you use the WebBrowser control’s webBrowser1_documentCompleted event handler to obtain your DocumentText, you should be fine.
label1 will now contain what you provide the web browser with…