我正在开发一个打开Web应用程序页面的Windows窗体。 我有义务使用COM AxWebBrowser实现这一目标。 问题是当在网页中执行window.Open()动作时,在我的axWebBrowser中打开新页面并显示另一个空白页面。我需要强制新窗口在空白页面中打开而不影响主页面页。 我尝试了下面的代码,但它没有正常工作:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MyProject.MyNamespace
{
public partial class PopupWindow : Form
{
#region Fields
private PopupWindow _popupWindow;
#endregion
#region Ctr
public PopupWindow()
{
this.InitializeComponent();
this.axWebBrowser.Silent = true;
this.axWebBrowser.NewWindow3 += new AxSHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(axWebBrowser_NewWindow3);
this.FormClosing += PopupWindow_FormClosing;
this.Shown += new EventHandler(PopupWindow_Shown);
}
private void axWebBrowser_NewWindow3(object sender, AxSHDocVw.DWebBrowserEvents2_NewWindow3Event e)
{
this._popupWindow = null;
this._popupWindow = new PopupWindow();
this._popupWindow.WindowState = FormWindowState.Maximized;
this._popupWindow.AXWebBrowser.RegisterAsBrowser = true;
e.ppDisp = this._popupWindow.AXWebBrowser.Application;
this._popupWindow.Visible = true;
}
#endregion
#region Properties
public AxSHDocVw.AxWebBrowser AXWebBrowser
{
get { return this.axWebBrowser; }
}
#endregion
#region Methods
private void PopupWindow_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
this.Hide();
}
private void PopupWindow_Shown(object sender, EventArgs e)
{
this.Size = new Size(this.Width + 2, this.Height + 2);
}
#endregion
}
}

感谢您的帮助!