如何在c#Web浏览器中创建新的Windows? [英] How Make New Windows in c# Web Browser ?

查看:71
本文介绍了如何在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.


这篇关于如何在c#Web浏览器中创建新的Windows?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆