简体   繁体   English

在DocumentCompleted中更改Web浏览器控件的大小

[英]Change size of web browser control in DocumentCompleted

I am having a web browser control in a winform. 我在Winform中有一个Web浏览器控件。 In order to show the web content completely (without scroll bars), I need to get the size of the web content in DocumentComplete event. 为了完全显示Web内容(没有滚动条),我需要在DocumentComplete事件中获取Web内容的大小。 And then resize(refresh) the winform. 然后调整(刷新)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. 如果Document.Window.Size不能解决问题, Document.Body.ScrollRectangle通常将为您工作。

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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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