Rt...
左键点击时用的StatuText中的Url,
但右键“在新窗口中打开”时,StatuText为空,如何用其他的方法解决?
或怎样捕获右键“在新窗口中打开”时超连接的Url???

解决方案 »

  1.   

    StatuText的对象问题。如果是自己做浏览器的话,那么它所针对的对象是新打开窗口的StatuText.
      

  2.   

    参考:http://www.codeproject.com/csharp/ExtendedWebBrowser.asp
      

  3.   

    谢谢各位,cocosoft() ,能详细些吗?
    我用的是2005的WebBrowser,不是老的axWebBrowser,网上资料说这两个控件好像有区别
      

  4.   

    回复人:yuan731() ( ) 信誉:100 2007-03-31 16:33:03 得分:0
    代码里写Url=""===================================
    问题就在于不知道右键“在新窗口中打开”时所点击连接的Url.....
      

  5.   

    所属的新窗口打开,只是对当前有WebBrowser的窗口进行重新实例化一下,然后,对经过重新实例化的窗口上的WebBrowser控件的NewWindow和WebBrowserNavigating或者WebBrowserNavigated事件赋值。所赋的值与现有的是一样的。当然,你不要将它所传递的值URL定死:)
      

  6.   

    You need to handle NewWindow2 event to create a new form and handle BeforeNavigate2 event in the new form. The webbrowser control in .Net 20 does not support opening new windows in the same application directly.
      

  7.   

    谢谢cocosoft(),呵呵,怪我没讲清楚,我做的是多页面浏览器,不是要将当前窗口在新窗口中打开,而是在网页中的连接上点击右键"在新窗口中打开",这时截取NewWindow事件,StatuText为空,如果不取消NewWindow事件,就会弹出IE,问题是地址是在哪传递的.
    左键点击连接时,StatuText值为所点击连接的地址,就可以直接Navigate了.
      

  8.   

    谢谢jiangsheng(蒋晟.Net[MVP]) ,呵呵,刚看了看,2005的WebBrowse没有BeforeNavigate2事件,我还不会写事件,呵呵....
      

  9.   

    BeforeNavigate2是.NET1.0及.NET 1.1下面的事件。如果在.NET 2.0下。你测试一下下面这段代码:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication2
    {
        public partial class Form1 : Form
        {
            public WebBrowser WebBrowser
            {
                get
                {
                    return webBrowser1;
                }
                set
                {
                    webBrowser1 = value;
                }
            }        public Form1()
            {
                InitializeComponent();
            }        private void toolStripButton1_Click(object sender, EventArgs e)
            {
                webBrowser1.Navigate(toolStripTextBox1.Text);
            }        private void webBrowser1_NewWindow(object sender, CancelEventArgs e)
            {
                Form1 f = new Form1();
                f.WebBrowser.Navigate(webBrowser1.StatusText);
                f.Show();
            }
        }
    }------------------------------------namespace WindowsApplication2
    {
        partial class Form1
        {
            /// <summary>
            /// 必需的设计器变量。
            /// </summary>
            private System.ComponentModel.IContainer components = null;        /// <summary>
            /// 清理所有正在使用的资源。
            /// </summary>
            /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }        #region Windows 窗体设计器生成的代码        /// <summary>
            /// 设计器支持所需的方法 - 不要
            /// 使用代码编辑器修改此方法的内容。
            /// </summary>
            private void InitializeComponent()
            {
                System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
                this.menuStrip1 = new System.Windows.Forms.MenuStrip();
                this.toolStrip1 = new System.Windows.Forms.ToolStrip();
                this.webBrowser1 = new System.Windows.Forms.WebBrowser();
                this.toolStripTextBox1 = new System.Windows.Forms.ToolStripTextBox();
                this.toolStripButton1 = new System.Windows.Forms.ToolStripButton();
                this.toolStrip1.SuspendLayout();
                this.SuspendLayout();
                // 
                // menuStrip1
                // 
                this.menuStrip1.Location = new System.Drawing.Point(0, 0);
                this.menuStrip1.Name = "menuStrip1";
                this.menuStrip1.Size = new System.Drawing.Size(657, 24);
                this.menuStrip1.TabIndex = 0;
                this.menuStrip1.Text = "menuStrip1";
                // 
                // toolStrip1
                // 
                this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
                this.toolStripTextBox1,
                this.toolStripButton1});
                this.toolStrip1.Location = new System.Drawing.Point(0, 24);
                this.toolStrip1.Name = "toolStrip1";
                this.toolStrip1.Size = new System.Drawing.Size(657, 25);
                this.toolStrip1.TabIndex = 1;
                this.toolStrip1.Text = "toolStrip1";
                // 
                // webBrowser1
                // 
                this.webBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
                this.webBrowser1.Location = new System.Drawing.Point(0, 49);
                this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
                this.webBrowser1.Name = "webBrowser1";
                this.webBrowser1.Size = new System.Drawing.Size(657, 292);
                this.webBrowser1.TabIndex = 2;
                this.webBrowser1.NewWindow += new System.ComponentModel.CancelEventHandler(this.webBrowser1_NewWindow);
                // 
                // toolStripTextBox1
                // 
                this.toolStripTextBox1.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest;
                this.toolStripTextBox1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.AllUrl;
                this.toolStripTextBox1.Name = "toolStripTextBox1";
                this.toolStripTextBox1.Size = new System.Drawing.Size(100, 25);
                // 
                // toolStripButton1
                // 
                this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
                this.toolStripButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton1.Image")));
                this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
                this.toolStripButton1.Name = "toolStripButton1";
                this.toolStripButton1.Size = new System.Drawing.Size(23, 22);
                this.toolStripButton1.Text = "toolStripButton1";
                this.toolStripButton1.Click += new System.EventHandler(this.toolStripButton1_Click);
                // 
                // Form1
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(657, 341);
                this.Controls.Add(this.webBrowser1);
                this.Controls.Add(this.toolStrip1);
                this.Controls.Add(this.menuStrip1);
                this.MainMenuStrip = this.menuStrip1;
                this.Name = "Form1";
                this.Text = "Form1";
                this.toolStrip1.ResumeLayout(false);
                this.toolStrip1.PerformLayout();
                this.ResumeLayout(false);
                this.PerformLayout();        }        #endregion        private System.Windows.Forms.MenuStrip menuStrip1;
            private System.Windows.Forms.ToolStrip toolStrip1;
            private System.Windows.Forms.WebBrowser webBrowser1;
            private System.Windows.Forms.ToolStripTextBox toolStripTextBox1;
            private System.Windows.Forms.ToolStripButton toolStripButton1;
        }
    }
      

  10.   

    The webbrowser control in .Net 20 does not support opening new windows in the same application directly. So you need to use the Activex interface.
      

  11.   

    TO: jiangsheng(蒋晟.Net[MVP])
    只能用老的axWebBrowser吗??
      

  12.   

    www.codeproject.com/csharp/ExtendedWebBrowser.asp