System.Windows.Forms.WebBrowser open links in same window or new window with same session(System.Windows.Forms.WebBrowser 在同一窗口或具有同一会话的新窗口中打开链接)
问题描述
When using the .NET WebBrowser control how do you open a link in a new window using the the same session (ie.. do not start a new ASP.NET session on the server), or how do you capture the new window event to open the URL in the same WebBrowser control?
I just spent an hour looking for the answer, so I though I would post the results here. You can use the SHDocVwCtl.WebBrowser_V1 object to capture the NewWindow event.
NOTE: Code from http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_21484555.html#discussion
//-------------------------------VB.NET Version:-------------------------------
Dim WithEvents Web_V1 As SHDocVwCtl.WebBrowser_V1
Private Sub Form_Load()
Set Web_V1 = WebBrowser1.Object
End Sub
Private Sub Web_V1_NewWindow(ByVal URL As String, ByVal Flags As Long, ByVal TargetFrameName As String, PostData As Variant, ByVal Headers As String, Processed As Boolean)
Processed = True
WebBrowser1.Navigate URL
End Sub
//-------------------------------C# Version-------------------------------
private SHDocVw.WebBrowser_V1 Web_V1; //Interface to expose ActiveX methods
private void Form1_Load(object sender, EventArgs e)
{
//Setup Web_V1 interface and register event handler
Web_V1 = (SHDocVw.WebBrowser_V1)this.webBrowser1.ActiveXInstance;
Web_V1.NewWindow += new SHDocVw.DWebBrowserEvents_NewWindowEventHandler(Web_V1_NewWindow);
}
private void Web_V1_NewWindow(string URL, int Flags, string TargetFrameName, ref object PostData,string Headers, ref bool Processed)
{
Processed = true; //Stop event from being processed
//Code to open in same window
this.webBrowser1.Navigate(URL);
//Code to open in new window instead of same window
//Form1 Popup = new Form1();
//Popup.webBrowser1.Navigate(URL);
//Popup.Show();
}
这篇关于System.Windows.Forms.WebBrowser 在同一窗口或具有同一会话的新窗口中打开链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:System.Windows.Forms.WebBrowser 在同一窗口或具有同一会话的新窗口中打开链接


基础教程推荐
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30