1

我正在开发一个打开 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
    }
}

谢谢您的帮助!

4

0 回答 0