简体   繁体   中英

Change size of web browser control in DocumentCompleted

I am having a web browser control in a winform. In order to show the web content completely (without scroll bars), I need to get the size of the web content in DocumentComplete event. And then resize(refresh) the winform.

void wbControl_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
    {
        wbControl.Height = wbControl.Document.Window.Size.Height;
        wbControl.Width = wbControl.Document.Window.Size.Width;
    }

But, Its not getting set from here. Old values remains the same.

If Document.Window.Size does not do the trick, Document.Body.ScrollRectangle will usually work for you.

I added some width and height when resizing the form because of the borders of the form, when resizing only the control itself this is not something you have to do.

private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    //If dockstyle = fill
    this.Width = webBrowser.Document.Body.ScrollRectangle.Width + 40;//Border
    this.Height = webBrowser.Document.Body.ScrollRectangle.Height + 40;//Border
    //If the control is not docked
    webBrowser.Size = webBrowser.Document.Body.ScrollRectangle.Size;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM