示例代码
public partial class Form1 : Form
{
public Form1() {
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) {
Thread t = new Thread(CreateWebBrowser);
t.SetApartmentState(ApartmentState.STA);
t.Start();
}
delegate void MyDelegate();
static WebBrowser _webBrowser = null;
static void CreateWebBrowser() {
_webBrowser = new WebBrowser();
_webBrowser.Location = new System.Drawing.Point(0, 100);
_webBrowser.MinimumSize = new System.Drawing.Size(20, 20);
_webBrowser.Name = "_webBrowser";
_webBrowser.Size = new System.Drawing.Size(400, 500);
_webBrowser.TabIndex = 2;
Form1.ActiveForm.Invoke((MyDelegate)delegate() {
Form1.ActiveForm.Controls.Add(_webBrowser);
});
_webBrowser.Navigate("http://www.google.com.hk");
}
}