.NET Framework 接收BeforeNavigate2事件BUG的替代方法

转载 2004年06月24日 10:40:00
[.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 JIT Engine 已经被证实的一个Bug

2005-3-9[.NET开发] .NET Framework JIT Engine 已经被证实的一个Bug # 首先感谢拓荒者为我们提供了错误样本。其次感谢kaneboy把这个错误报告上去,并告诉我...
  • zdg
  • zdg
  • 2005年03月10日 19:44
  • 2794

VS 2012 标配 Asp.net MVC 和 Entity Framework - mybatisnet 可能就显得路子野 了

VS 2012 标配 Asp.net MVC 和 Entity Framework - mybatisnet 可能就显得路子野 了
  • sleks
  • sleks
  • 2016年01月23日 21:23
  • 2307

.NET 程序在 Windows XP 下调用 SHA512CryptoServiceProvider 方法报 PlatformNotSupportedException 异常

.NET 程序在 Windows XP 下调用 SHA512CryptoServiceProvider 方法报 PlatformNotSupportedException 异常 ...
  • xiaominggunchuqu
  • xiaominggunchuqu
  • 2017年11月15日 12:03
  • 98

C#事件之 发布符合 .NET Framework 准则的事件

下面的过程演示了如何将符合标准 .NET Framework 模式的事件添加到您的类和结构中。 EventHandler delegate, which is defined as follows:...
  • chen578157939
  • chen578157939
  • 2014年03月08日 18:15
  • 576

NET Framework 4.5 中的新增功能

地址: http://msdn.microsoft.com/library/ms171868%28VS.110%29.aspx#web ...
  • hliq5399
  • hliq5399
  • 2013年09月23日 14:42
  • 7502

如何让 WebBrowser控件 使用BeforeNavigate2(...)屏蔽特定页面

这是俺提问的一个帖子,如下:norsd等级:可用分等级:贫农总技术分:932总技术分排名:20992结帖率:100.00%BeforeNavigate2(...) 中的参数 *Cancel=VARIA...
  • norsd
  • norsd
  • 2008年12月11日 17:00
  • 8053

.net微信公众号开发——消息与事件

本文介绍如何处理微信公众号开发中的消息与事件,包括:(1)消息(事件)概况;(2)验证消息的真实性;(3)解析消息;(4)被动回复消息;(5)发送其他消息。...
  • xrwang
  • xrwang
  • 2015年03月11日 19:31
  • 2634

[.Net码农][hystar整理]Entity Framework 教程

http://www.cnblogs.com/lsxqw2004/archive/2009/05/31/1495240.html 预备知识 LINQ技术 LINQ是.NET 3....
  • CrackLibby
  • CrackLibby
  • 2015年09月05日 01:27
  • 819

Python 调用.net framework写的类库的方法

 版权声明请尊重原创作品。转载请保持文章完整性,并以超链接形式注明原始作者“tingsking18”和主站点地址,方便其他朋友提问和指正。 Python 调用.net framework写的类库的方法...
  • tingsking18
  • tingsking18
  • 2009年04月29日 09:21
  • 3391

如何得到 .NET Framework 安装的文件夹?

.NET 提供了得到系统文件夹的方法,如System.Environment.SystemDirectory等,但是,.NET Framework 的安装文件夹可以通过下面的方法得到,但是需要注意,此...
  • net_lover
  • net_lover
  • 2007年08月26日 16:45
  • 5821
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:.NET Framework 接收BeforeNavigate2事件BUG的替代方法
举报原因:
原因补充:

(最多只允许输入30个字)