Resizing a WebBrowser Control

I have a WebBrowser in my form that accesses a website that is too wide for the control. I would like to know if there is a way to resize the control to fit the website. Seems simple, but I haven't found a way yet. I know how to resize a control, I just need to find the width of the website. Just as if you press the green button in safari, it will automatically resize the window to the desired size.

+4
source share
5 answers

You must have access to the size of the WebBrowser document and get its size through WebBrowser.Document.Window.Size.

I would use the WebBrowser Controls DocumentCompleted event to wait for the page to load, and then use the resize code to resize the webControl container with that size.

Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted WebBrowser1.Size = WebBrowser1.Document.Body.ScrollRectangle.Size End Sub 
+3
source

Answered here : use WebBrowser.Document.Body.ScrollRectangle.Size instead of WebBrowser.Document.Window.Size . I work like a charm for me.

0
source
  • The first step should be to see if you can even resize the control at all.
  • Step two is to see if you can find the size that the website will like.
  • Step three is the size or maximum screen size, whichever is smaller, minus any chrome, and change the size of the control to that size.
-1
source

It’s best to make sure that WebBrowser uses as much space (Dock.Fill) in the form from get-go, so if the user full-screen mode maximizes the application, it gets a lot of space and if they want less for small sites, they can change the size your application, but they want to. This is how all browsers work.

-1
source
 var webBrowser = new WebBrowser(); // the magic!!! webBrowser.Dock = DockStyle.Fill; form.get_Controls().Add(webBrowser); webBrowser.Navigate('http://a.com/'); 
-2
source

All Articles