这是我当前的代码:https://hastebin.com/ifejusezat.cs
这是我看到的屏幕截图:https://gyazo.com/2ee9b1210649ca8ec61e3fa7e645a286
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
BrowserView browserView = new WinFormsBrowserView();
Controls.Add((Control)browserView);
browserView.Browser.LoadURL("http://www.google.com");
}
private void Form1_Load(object sender, EventArgs e)
{
BrowserView browserView = new WinFormsBrowserView(BrowserFactory.Create());
Control browserWindow = (Control)browserView;
browserWindow.Dock = DockStyle.Fill;
Controls.Add(browserWindow);
}
}
答案 0 :(得分:0)
更新后的答案:这是我完整的Form1.cs(直接从teamdev website获取),并且无需调整大小即可工作(参见图片)。
using DotNetBrowser;
using DotNetBrowser.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WinFormsSampleCSLightweight
{
public partial class Form1 : Form
{
private readonly BrowserView browserView;
public Form1()
{
InitializeComponent();
browserView = new WinFormsBrowserView(BrowserFactory.Create(BrowserType.LIGHTWEIGHT));
Controls.Add((Control)browserView);
browserView.Browser.LoadURL("http://www.google.com");
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (browserView != null)
{
browserView.Dispose();
browserView.Browser.Dispose();
}
}
}
}
原始答案: 您可以在浏览器视图上尝试UpdateSize方法。
browserView.UpdateSize(someWidth, someHeight);
或者您可以尝试调整查看的文档的大小。
public void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//For the case when the control's Dock property is DockStyle.Fill
this.Width = WebBrowser.Document.Body.ScrollRectangle.Width + 40; //40 is for border
this.Height = WebBrowser.Document.Body.ScrollRectangle.Height + 40; //40 is for border
//For the case when the control is not docked
WebBrowser.Size = WebBrowser.Document.Body.ScrollRectangle.Size;
}
答案 1 :(得分:0)
如果您使用的是DotNetBrowser 1.9,请使用控件属性将Dock设置为DockFill
Control browserControl = (Control)browserView;
browserControl.Dock = DockStyle.Fill;
Controls.Add(browserControl);