Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent scrollbars with WPF WebBrowser displaying content

I'm using the WPF WebBrowser component to display some very simple HTML content. However, since I don't know the content size in advance, I'm currently getting scrollbars on the control when I load certain datasets.

Basically, how can I force (or otherwise effect the equivalent of forcing) the WebBrowser to expand in size so that all content is displayed without the need for scrollbars?

like image 499
Kevin Montrose Avatar asked Dec 16 '09 00:12

Kevin Montrose


2 Answers

I guess you can get width and height of the webbrowser component content through its Document property which should be of mshtml.HTMLDocument type. I believe you should be able to use body or documentElement properties to get needed sizes; smth like this:

mshtml.HTMLDocument htmlDoc = webBrowser.Document as mshtml.HTMLDocument;
if (htmlDoc != null && htmlDoc.body != null)
{
    mshtml.IHTMLElement2 body = (mshtml.IHTMLElement2)htmlDoc.body;
    webBrowser.Width = body.scrollWidth;
    webBrowser.Height = body.scrollHeight;
}

hope this helps, regards

like image 171
serge_gubenko Avatar answered Nov 04 '22 13:11

serge_gubenko


The problem with previous solution is that it changes the control size and since the browser control cannot be clipped and is always on top of other WPF elements, it may cover the other elements.

Here is my solution:

Dim body = CType(WebBrowserControl.Document, mshtml.HTMLDocumentClass)
body.documentElement.style.overflow = "hidden"

Regards,

Assaf

like image 40
Assaf S. Avatar answered Nov 04 '22 14:11

Assaf S.