.NET Framework 接收BeforeNavigate2事件BUG的替代方法
来源:互联网 发布:4g网络变成2g 编辑:程序博客网 时间:2024/05/21 02:48
[.NET Framework 接收BeforeNavigate2事件BUG的替代方法]
????这是一篇微软网络上找到的文章,现在也许不适用了,但如果仍用.NET Framework 1.0,则只有这个方法可以解决这个问题了。
Liju Thomas [@online.microsoft.com]
Regarding BeforeNavigate2 it a bug as mentioned in the KB article.
But you can connect directly to IWebBrowserEvents (NOT IWebBrowserEvents2)
and sink to the BeforeNavigate event.
sample code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Data;
using SHDocVw;
namespace InetTest
{
????///
????/// Summary description for Form1.
????///
????public class Form1 : System.Windows.Forms.Form, DWebBrowserEvents
????{
????????private AxSHDocVw.AxWebBrowser axWebBrowser1;
????????private System.Windows.Forms.Button button1;
????????private System.Windows.Forms.Label label1;
????????private UCOMIConnectionPoint icp;
????????private int cookie = -1;
????????///
????????/// Required designer variable.
????????///
????????private System.ComponentModel.Container components = null;
????????private Object obj;
????????public Form1()
????????{
????????????//
????????????// Required for Windows Form Designer support
????????????//
????????????InitializeComponent();
????????????// Sink to webbrowser events
????????????UCOMIConnectionPointContainer icpc =
????????????????(UCOMIConnectionPointContainer)axWebBrowser1.GetOcx();
????????????Guid g = typeof(DWebBrowserEvents).GUID;
????????????icpc.FindConnectionPoint(ref g, out icp);
????????????icp.Advise(this, out cookie);
????????}
????????///
????????/// Clean up any resources being used.
????????///
????????protected override void Dispose( bool disposing
????????{
????????????if( disposing
????????????{
????????????????// Release event sink
????????????????if (-1 != cookie) icp.Unadvise(cookie);
????????????????cookie = -1;
????????????????if (components != null)
????????????????{
????????????????????components.Dispose();
????????????????}
????????????}
????????????base.Dispose( disposing ;
????????}
#region Windows Form Designer generated code
????????///
????????/// Required method for Designer support - do not modify
????????/// the contents of this method with the code editor.
????????///
????????private void InitializeComponent()
????????{
????????????System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(Form1));
????????????this.axWebBrowser1 = new AxSHDocVw.AxWebBrowser();
????????????this.button1 = new System.Windows.Forms.Button();
????????????this.label1 = new System.Windows.Forms.Label();
????????????
((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).BeginInit()
;
????????????this.SuspendLayout();
????????????//
????????????// axWebBrowser1
????????????//
????????????this.axWebBrowser1.Enabled = true;
????????????this.axWebBrowser1.Location = new System.Drawing.Point(16, 8);
????????????this.axWebBrowser1.OcxState =
((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowser1.OcxS
tate"));
????????????this.axWebBrowser1.Size = new System.Drawing.Size(456, 208);
????????????this.axWebBrowser1.TabIndex = 0;
????????????//
????????????// button1
????????????//
????????????this.button1.Location = new System.Drawing.Point(16, 232);
????????????this.button1.Name = "button1";
????????????this.button1.TabIndex = 1;
????????????this.button1.Text = "button1";
????????????this.button1.Click += new System.EventHandler(this.button1_Click);
????????????//
????????????// label1
????????????//
????????????this.label1.Location = new System.Drawing.Point(112, 232);
????????????this.label1.Name = "label1";
????????????this.label1.Size = new System.Drawing.Size(344, 23);
????????????this.label1.TabIndex = 2;
????????????this.label1.Text = "label1";
????????????//
????????????// Form1
????????????//
????????????this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
????????????this.ClientSize = new System.Drawing.Size(480, 273);
????????????this.Controls.AddRange(new System.Windows.Forms.Control[] {
???????????????????????????????????????????????????????????????????????? this.label1,
???????????????????????????????????????????????????????????????????????? this.button1,
???????????????????????????????????????????????????????????????????????? this.axWebBrowser1});
????????????this.Name = "Form1";
????????????this.Text = "Form1";
????????????
((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).EndInit();
????????????this.ResumeLayout(false);
????????}
#endregion
????????// DWebBrowserEvents Implementation
????????public void BeforeNavigate(string url, int flags,
????????????string targetFrameName, ref object postData,
????????????string headers, ref bool cancel)
????????{
????????????label1.Text = "BeforeNavigate to " + url;
????????}
????????public void NavigateComplete(string url) { }
????????public void StatusTextChange(string text) { }
????????public void ProgressChange(int progress, int progressMax) { }
????????public void DownloadComplete() { }
????????public void CommandStateChange(int command, bool enable) { }
????????public void DownloadBegin() { }
????????public void NewWindow(string url, int flags, string targetFrameName, ref
object postData, string headers, ref bool processed) { }
????????public void TitleChange(string text) { }
????????public void FrameBeforeNavigate(string url, int flags, string
targetFrameName, ref object postData, string headers, ref bool cancel) { }
????????public void FrameNavigateComplete(string url) { }
????????public void FrameNewWindow(string url, int flags, string targetFrameName,
ref object postData, string headers, ref bool processed) { }
????????public void Quit(ref bool Cancel) { }
????????public void WindowMove() { }
????????public void WindowResize() { }
????????public void WindowActivate() { }
????????public void PropertyChange(string property) { }
????????///
????????/// The main entry point for the application.
????????///
????????[STAThread]
????????static void Main()
????????{
????????????Application.Run(new Form1());
????????}
????????private void button1_Click(object sender, System.EventArgs e)
????????{
????????????axWebBrowser1.Navigate ("www.msn.com", ref obj, ref obj, ref obj, ref
obj);
????????}
????}
}
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.
(C)2001 Microsoft Corporation. All rights reserved.
????这是一篇微软网络上找到的文章,现在也许不适用了,但如果仍用.NET Framework 1.0,则只有这个方法可以解决这个问题了。
Liju Thomas [@online.microsoft.com]
Regarding BeforeNavigate2 it a bug as mentioned in the KB article.
But you can connect directly to IWebBrowserEvents (NOT IWebBrowserEvents2)
and sink to the BeforeNavigate event.
sample code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Data;
using SHDocVw;
namespace InetTest
{
????///
????/// Summary description for Form1.
????///
????public class Form1 : System.Windows.Forms.Form, DWebBrowserEvents
????{
????????private AxSHDocVw.AxWebBrowser axWebBrowser1;
????????private System.Windows.Forms.Button button1;
????????private System.Windows.Forms.Label label1;
????????private UCOMIConnectionPoint icp;
????????private int cookie = -1;
????????///
????????/// Required designer variable.
????????///
????????private System.ComponentModel.Container components = null;
????????private Object obj;
????????public Form1()
????????{
????????????//
????????????// Required for Windows Form Designer support
????????????//
????????????InitializeComponent();
????????????// Sink to webbrowser events
????????????UCOMIConnectionPointContainer icpc =
????????????????(UCOMIConnectionPointContainer)axWebBrowser1.GetOcx();
????????????Guid g = typeof(DWebBrowserEvents).GUID;
????????????icpc.FindConnectionPoint(ref g, out icp);
????????????icp.Advise(this, out cookie);
????????}
????????///
????????/// Clean up any resources being used.
????????///
????????protected override void Dispose( bool disposing
????????{
????????????if( disposing
????????????{
????????????????// Release event sink
????????????????if (-1 != cookie) icp.Unadvise(cookie);
????????????????cookie = -1;
????????????????if (components != null)
????????????????{
????????????????????components.Dispose();
????????????????}
????????????}
????????????base.Dispose( disposing ;
????????}
#region Windows Form Designer generated code
????????///
????????/// Required method for Designer support - do not modify
????????/// the contents of this method with the code editor.
????????///
????????private void InitializeComponent()
????????{
????????????System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(Form1));
????????????this.axWebBrowser1 = new AxSHDocVw.AxWebBrowser();
????????????this.button1 = new System.Windows.Forms.Button();
????????????this.label1 = new System.Windows.Forms.Label();
????????????
((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).BeginInit()
;
????????????this.SuspendLayout();
????????????//
????????????// axWebBrowser1
????????????//
????????????this.axWebBrowser1.Enabled = true;
????????????this.axWebBrowser1.Location = new System.Drawing.Point(16, 8);
????????????this.axWebBrowser1.OcxState =
((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowser1.OcxS
tate"));
????????????this.axWebBrowser1.Size = new System.Drawing.Size(456, 208);
????????????this.axWebBrowser1.TabIndex = 0;
????????????//
????????????// button1
????????????//
????????????this.button1.Location = new System.Drawing.Point(16, 232);
????????????this.button1.Name = "button1";
????????????this.button1.TabIndex = 1;
????????????this.button1.Text = "button1";
????????????this.button1.Click += new System.EventHandler(this.button1_Click);
????????????//
????????????// label1
????????????//
????????????this.label1.Location = new System.Drawing.Point(112, 232);
????????????this.label1.Name = "label1";
????????????this.label1.Size = new System.Drawing.Size(344, 23);
????????????this.label1.TabIndex = 2;
????????????this.label1.Text = "label1";
????????????//
????????????// Form1
????????????//
????????????this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
????????????this.ClientSize = new System.Drawing.Size(480, 273);
????????????this.Controls.AddRange(new System.Windows.Forms.Control[] {
???????????????????????????????????????????????????????????????????????? this.label1,
???????????????????????????????????????????????????????????????????????? this.button1,
???????????????????????????????????????????????????????????????????????? this.axWebBrowser1});
????????????this.Name = "Form1";
????????????this.Text = "Form1";
????????????
((System.ComponentModel.ISupportInitialize)(this.axWebBrowser1)).EndInit();
????????????this.ResumeLayout(false);
????????}
#endregion
????????// DWebBrowserEvents Implementation
????????public void BeforeNavigate(string url, int flags,
????????????string targetFrameName, ref object postData,
????????????string headers, ref bool cancel)
????????{
????????????label1.Text = "BeforeNavigate to " + url;
????????}
????????public void NavigateComplete(string url) { }
????????public void StatusTextChange(string text) { }
????????public void ProgressChange(int progress, int progressMax) { }
????????public void DownloadComplete() { }
????????public void CommandStateChange(int command, bool enable) { }
????????public void DownloadBegin() { }
????????public void NewWindow(string url, int flags, string targetFrameName, ref
object postData, string headers, ref bool processed) { }
????????public void TitleChange(string text) { }
????????public void FrameBeforeNavigate(string url, int flags, string
targetFrameName, ref object postData, string headers, ref bool cancel) { }
????????public void FrameNavigateComplete(string url) { }
????????public void FrameNewWindow(string url, int flags, string targetFrameName,
ref object postData, string headers, ref bool processed) { }
????????public void Quit(ref bool Cancel) { }
????????public void WindowMove() { }
????????public void WindowResize() { }
????????public void WindowActivate() { }
????????public void PropertyChange(string property) { }
????????///
????????/// The main entry point for the application.
????????///
????????[STAThread]
????????static void Main()
????????{
????????????Application.Run(new Form1());
????????}
????????private void button1_Click(object sender, System.EventArgs e)
????????{
????????????axWebBrowser1.Navigate ("www.msn.com", ref obj, ref obj, ref obj, ref
obj);
????????}
????}
}
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.
(C)2001 Microsoft Corporation. All rights reserved.
- .NET Framework 接收BeforeNavigate2事件BUG的替代方法
- FireFox中替代onpropertychange事件的方法
- VC6重载BeforeNavigate2和DocumentComplete函数方法
- VC6重载BeforeNavigate2和DocumentComplete函数方法 .
- .NET Framework中的事件
- C#事件之 发布符合 .NET Framework 准则的事件
- .net framework 3.5的分部方法
- 查看.Net Framework版本的方法
- 查看.Net Framework版本的方法
- 查看.Net Framework版本的方法
- 查看.Net Framework版本的方法(zz)
- 查看.Net Framework版本的方法
- .NET FrameWork获取电脑屏幕分辨率的方法
- Win10安装.NET Framework 3.5的方法
- 替代goto的方法
- Externalizable 的替代方法
- 替代setLatestEventInfo()的方法
- 认识.NET Framework事件处理
- 在U盘上创建一个Linux系统的步骤
- 安装GCC3.4过程
- 端午
- 失败得要命,我想我还是太嫩了。
- 纸上谈分页
- .NET Framework 接收BeforeNavigate2事件BUG的替代方法
- jsp页面的中文在dreamweaver中显示为乱码的问题解决
- 彻底明白Java的IO系统(zt)
- 试试 AND 开张
- 浅析Intel/AMD在CPU市场的龙争虎斗
- 浮点运算都存在精度损失
- asp.net server side using JavaScript
- Linux下Samba服务器的配置过程
- 偶觉得这个Blog应该有所改进、有所特色