我在winform中有一个Web浏览器控件。为了完整地显示Web内容(没有滚动条),我需要在DocumentComplete事件中获取Web内容的大小。然后调整(刷新)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;
}
但是,它不会从这里开始。旧的价值观保持不变。
答案 0 :(得分:1)
如果Document.Window.Size
无法解决问题,Document.Body.ScrollRectangle
通常适合您。
由于表单的边框,我在调整表单大小时添加了一些宽度和高度,当仅调整控件本身时,这不是你必须做的事情。
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;
}