如何在c#Web浏览器中创建新的Windows?

如何在c#Web浏览器中创建新的Windows?

问题描述:

如何制作新的Windows网页浏览器?

当我使用此代码

how make new windows web browser ?
when i use this code

private void webBrowser1_NewWindow(object sender, CancelEventArgs e)
       {
           Form k = new Form1();
           k.Show();
       }



打开我的项目页面并打开Internet Explorer如何关闭Internet Explorer?请帮我解决你的代码。


open a page of my project and open internet explorer how can i close the internet explorer ? please help me with your codes .

这是一个PITA,但是,它还不错:

This is a bit of a PITA, but, it's not too bad:
private void myWebBrowser_NewWindow(object sender, CancelEventArgs e)
    {
    Debug.WriteLine("New Window request");
    WebBrowser browser = sender as WebBrowser;
    if (browser != null)
        {
        HtmlElement element = browser.Document.ActiveElement;
        string newUrl = element.GetAttribute("href");
        browser.Navigate(newUrl);
        e.Cancel = true;
        }
    }



捕获新窗口请求,并回收当前窗口而不是打开IE来处理请求。如果您想要打开表单的新实例,只需在我导航现有浏览器的位置创建它,并指示您的表单使用新URL。


That "traps" the new window request, and recycles the current window instead of opening IE to handle the request. If you want to open a new instance of your form instead, just create it where I navigate the existing browser, and instruct your form to use the new URL.