Solved

Resize a WebBrowser control based on the Website page

Posted on 2014-01-24
4
7,194 Views
Last Modified: 2014-02-08
Hi,

Is there a way to resize a WebBrowser control (which in turn will resize a WinForm or WPF Window) based on a default size of a webpage.   For example if I click on a link in IE it will bring up a pop with a different size and width then my web browser.   I would like to make a quick app that will directly open this pop and will re-size itself to the webpage.   I hope this makes sense.   Thanks.

David
0
Comment
Question by:davidst98
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

Expert Comment

by:Matthew Kelly
ID: 39807863
There is no such thing as a default size of a webpage. You would need to know what content piece you were trying to size to on the page which would require knowing exactly what pages you are navigating to and what elements to look for.

Take this EE page for example. You may say, I want it to size so I see only the right and left hand navigation with everything else on either side of it cut off.

So there is a "bodyWrapper" id DIV you could size to, but that is encapsulated in other div containers that are set to 100%.

Web pages are designed to size to the browser, not the other way around. If your WebBrowser control is only setup to go to webpages you control you could do it by getting the width/height of a container object on the page.
0
 

Author Comment

by:davidst98
ID: 39808029
Hi Matthew,  thanks for the response.  I'm a little confused.  How do pop web pages are able to change the size of the web browser and also remove menu and toolbars?

David
0
 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 39808035
0
 
LVL 18

Accepted Solution

by:
Matthew Kelly earned 500 total points
ID: 39808119
Ok, this needs a lot more work, such as setting a maximum width/height etc, but here is a general concept that will resize a webbrowser control to the size of a webpage based on elimination of scroll bar space.

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            webBrowser1.Navigate(new Uri("http://google.com"));

        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            if (HasHorizontalScrollbar)
            {
                webBrowser1.Size = new Size(webBrowser1.Document.Body.ScrollRectangle.Width, webBrowser1.Document.Body.ScrollRectangle.Height);
                Form1.ActiveForm.Size = new Size(webBrowser1.Document.Body.ScrollRectangle.Width, webBrowser1.Document.Body.ScrollRectangle.Height);
            }
        }

        public bool HasHorizontalScrollbar
        {
            get
            {
                var width1 = webBrowser1.Document.Body.ScrollRectangle.Width;
                var width2 = webBrowser1.Document.Window.Size.Width;

                return width1 > width2;
            }
        }
    }
}

Open in new window

0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question