.net 如何使用 WebBrowser 控件“在新窗口中打开”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/118203/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to "Open in New Window" using WebBrowser control?
提问by Chris Pietschmann
When you use the WebBrowser control in .NET you can "embed" an instance of IE in your application, essentially making your own IE-based Web Browser.
当您在 .NET 中使用 WebBrowser 控件时,您可以在您的应用程序中“嵌入”一个 IE 实例,实质上是制作您自己的基于 IE 的 Web 浏览器。
Does anyone know how to make any new windows created (like when the user selects "Open in New Window" from the context menu) open up in another Window of Your Web Browser Application, instead of the computers default browser??
有谁知道如何在您的 Web 浏览器应用程序的另一个窗口而不是计算机默认浏览器中打开任何创建的新窗口(例如当用户从上下文菜单中选择“在新窗口中打开”时)?
采纳答案by ManojN
Maybe the Source Code from this CodeProject article can help:
也许这篇 CodeProject 文章中的源代码可以提供帮助:
回答by JKueck
I did this a long time ago in VB.
我很久以前在 VB 中这样做过。
From what I remember, when a NewWindow2 event was fired by the control, we would cancel the original request and open a separate VB form that contained another instance of the WebBrowser control pointed at the requested URL.
根据我的记忆,当控件触发 NewWindow2 事件时,我们将取消原始请求并打开一个单独的 VB 窗体,其中包含指向所请求 URL 的 WebBrowser 控件的另一个实例。
I did a quick google search and it seems like maybe this event isn't as easy to access in .Net. Take a look here for a possible solution.
我做了一个快速的谷歌搜索,似乎这个事件在 .Net 中不太容易访问。 在这里查看可能的解决方案。
回答by Chris Pietschmann
There's a code sample here that contains code for adding the NewWindow2 event to the WebBrowser control. It sure would be nice if they added this event to the WebBrowser control itself.
此处有一个代码示例,其中包含用于将 NewWindow2 事件添加到 WebBrowser 控件的代码。如果他们将此事件添加到 WebBrowser 控件本身,那肯定会很好。
回答by John Sims
This site has the best solution I've found if you're using the .net version of the webbrowser control
如果您使用的是 .net 版本的 webbrowser 控件,则此站点具有我发现的最佳解决方案
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/f497f8a5-dac8-48cb-9fce-7936c9389f09
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/f497f8a5-dac8-48cb-9fce-7936c9389f09

