안녕하세요 저는 폼의 나머지 부분에서 올바른 스레드에 두 개의 웹 브라우저를 만들려고합니다. 하나는 tabpage1로 이동하고 다른 하나는 tabpage2에 추가됩니다. 첫 번째 브라우저는 page1을 잘 생성하지만 두 번째 브라우저는 추가되지 않고 "WebBrowser 컨트롤에 대한 창 핸들을 가져올 수 없습니다. 창없는 ActiveX 컨트롤은 지원되지 않습니다." 일어난다. 를 heres 내 코드 :두 번째 탭 페이지에 웹 브라우저 호출하기 Visual C#
private Thread t;
WebBrowser webBrowser1, webBrowser2;
public delegate void Addc1(Control o);
public delegate void Addc2(Control o);
public Addc1 AddControl1;
public Addc2 AddControl2;
public Form1()
{
InitializeComponent();
AddControl1 = new Addc1(AddTabControl1);
AddControl2 = new Addc2(AddTabControl2);
}
private void button2_Click(object sender, EventArgs e)
{
t = new Thread(new ThreadStart(this.UIStart));
t.SetApartmentState(ApartmentState.STA);
t.Start();
}
public void UIStart()
{
WebBrowser webBrowser1 = new WebBrowser();
webBrowser1.Location = new System.Drawing.Point(1,1);
webBrowser1.Size = new System.Drawing.Size(936, 35);
webBrowser1.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.webBrowser2_DocumentCompleted);
tabPage1.Invoke(AddControl1, new Object[] { webBrowser1 });
WebBrowser webBrowser2 = new WebBrowser();
webBrowser2.Location = new System.Drawing.Point(1,1);
webBrowser2.Size = new System.Drawing.Size(936, 935);
webBrowser2.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.webBrowser2_DocumentCompleted);
tabPage2.Invoke(AddControl2, new Object[] { wedBrowser2 });
webBrowser1.Navigate("www.ask.com");
webBrowser2.Navigate("www.google.com");
}
public void AddTabControl1(Control o)
{
tabPage1.Controls.Add(o);
}
public void AddTabControl2(Control o)
{
tabPage2.Controls.Add(o);
}
}
내가 webbrowser1 만들고 이동하지만, 다른 하나는 페이지 2의 컨트롤에 추가하지만 만들어지지 않습니다 것이라고 말했다있다. 어떤 아이디어? 덕분에 당신은 여러 스레딩 규칙을 위반하고