我在处理一个网站内信息时遇到了问题,希望大虾们赐教.
我在一个form中放了一个webBrowser,打开一个网站,网页上需要输入用户名密码,登陆后对里面的数据进行处理,可是,登陆的时候,新的页面是由ie浏览器打开的,我在form中就无法对其操作了,请问webBrowser有什么方法能使登陆后的页面在本身打开的吗?可以的话,请给个简单的例子,不甚感谢!

解决方案 »

  1.   

    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).NewWindow2 += new SHDocVw.DWebBrowserEvents2_NewWindow2EventHandler(Form1_NewWindow2);        }
            private void button1_Click(object sender, EventArgs e)
            {
                this.webBrowser1.Navigate("www.google.cn");
            }        void Form1_NewWindow2(ref object ppDisp, ref bool Cancel)
            {
                Form1 frm = new Form1();
                ppDisp = frm.webBrowser1.ActiveXInstance;
                frm.Show();
            }       
        }
    }
      

  2.   

    谢谢你的帮助,不过有个地方通不过,请帮一下,
    错误 1 找不到类型或命名空间名称“SHDocVw”(是否缺少 using 指令或程序集引用?) C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\loaddiaodu\loaddiaodu\Form1.cs 23 50 loaddiaodu
      

  3.   

    恩,可以了,可是是重新打开了一个form,有没有办法就在自身form里打开呢?另外,在弹出来的form里的页面上的连接点击后,又是由ie打开了,我想让里面所有级的连接都在form里打开的,请问该如何实现?我是新手,对程序还不太熟,却要赶程序,十分感谢你,请再帮我一下
      

  4.   

    [code=C#]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("www.google.cn");
            }               
        }
    }[/code]
      

  5.   

    .net2.0
    中部需要引用SHDocVw.dll