歌舞程序

导航

解决WebBrowser中打开链接调用IE窗口问题

应用Webbrowser显示网页时,点击里面的链接,可能调用IE来打开,而不是使用Webbrowser来打开。为解决此问题。经大量Google,baidu后,寻找到以下几种方案,我使用第一种,其余未实践,供参考:
一、使用NewWindow3 事件
引入SHDocVw.dll//本想将这个dll文件一起打包提供下载,但没找到粘贴附件的地方。需要的朋友自己去找了。
using SHDocVw;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
namespace WindowsApplication24
...{
    public partial class Form1 : Form
    ...{
       
        public Form1()
        ...{
            InitializeComponent();
            this.webBrowser1.Navigate("about:blank");
            (this.webBrowser1.ActiveXInstance as SHDocVw.WebBrowser).NewWindow3 += new SHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(Form1_NewWindow3);

        }

        void Form1_NewWindow3(ref object ppDisp, ref bool Cancel, uint dwFlags, string bstrUrlContext, string bstrUrl)
        ...{
            Cancel = true;
            this.webBrowser1.Navigate(bstrUrl);
        }
        private void button1_Click(object sender, EventArgs e)
        ...{
            this.webBrowser1.Navigate("http://www.google.cn/");
        }

       

      
    }
}

二。给出一个链接:http://hi.baidu.com/zhitenglin/blog/item/5d1614f3b09fe6cc0a46e011.html

posted on 2009-07-31 21:15  歌舞程序  阅读(1860)  评论(1编辑  收藏  举报