.NET Framework Receives alternatives to BeforenaviGate2 Event Bug

zhaozj2021-02-16  47

[.NET Framework Receives Alternative Methods for BeforenaviGate2 Event BUG]

???? This is an article found on the Microsoft network, and now may not apply, but if you still use .NET Framework 1.0, only this method can solve this problem.

Liju thomas [@ online.microsoft.com]

Regarding beforenavigate22 it a bug as personed in the kb article.

But you can connect directly to iWebBrowserevents (not iWebBrowseRevents2)

And sink to the beforenavigate.

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. ???????? ///

????????????????prate 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 ???????? {

???????????? f (disposing)

???????????? {

??????????????????????????????????????????????????????????????????????????????????????????????????????????

????????????????? IF (-1! = cookie) icp.unadvise (cookie);

???????????????? cookie = -1;

???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? i (Components!

???????????????? {

???????????????????? 2012.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.axwebbBBBROWSER1 = 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 ();

???????????? //

????????????? // AxwebBBROWSER1

???????????? //

???????????? this.axwebbrowser1.enabled = TRUE

???????????? this.axwebbrowser1.location = new system.drawing.point (16, 8);

???????????? this.axwebbbrowser1.ocxState =

((System.Windows.Forms.Axhost.State) (Resources.getObject ("AxWebBrowser1.ocxs

Tate "));

???????????? this.axwebbrowser1.size = new system.drawing.size (456, 208);

???????????? this.axwebBBBBROWSER1.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,

??????????????????????????????????????????? ???????????????????????his.axwebbrowser1};

???????????? this.name = "form1";

???????????? this.text = "form1";

????????????

(System.comPonentModel.isupportInitialize) (this.Axwebbrowser1)). Endinit ();

???????????? this.ResumeLayout (FALSE);

????????}

#ndregion

???????? // dwebbrowserevents implemementation

???????? 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 propresschange (int progress, int propressmax) {}

???????? 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 title (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 TargetFramen),

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 printychange (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.

转载请注明原文地址:https://www.9cbs.com/read-20857.html

New Post(0)