windowclosing没有开火 [英] windowclosing not firing

查看:106
本文介绍了windowclosing没有开火的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




在vb.net中,如果你添加一个webbrowser控件,windowclosing事件就不会发生火灾。我到处寻找一个解决方案而不是我得到更多的人

说我有同样的问题。


我发现这个...有人请转换这个到VB.NET给我们一个

一线希望或者提供一个解决方案。


如果你实现了axWebBrowser,你会发现WindowClosing事件没有'b
$ b fire。这是解决方法,我确认是有效的。


1.在System.Windows.Forms.Form类的正下方添加另一个类

来自SHDocVw .DWebBrowserEvents2。例如:\


公共类IEEvents:SHDocVw.DWebBrowserEvents2

{}


2.保存文件并转到课堂视图(查看|班级视图菜单选项)。转到树视图中的

IEEvents类并展开它。继续扩大孩子

直到你看到''DWebBrowserEvents''。右键单击并选择添加实现

接口''菜单选项。


3.应通过上述步骤生成WindowClosing事件的方法。对方法应用

''DispId''属性,如下所示:


[DispId(0x00000107)]

public void WindowClosing(bool IsChildWindow,ref bool取消)

{

//事件处理程序的消息框工作

MessageBox.Show(" Closing Event"," IE",MessageBoxButtons.OK,

MessageBoxIcon.Exclamation);

}


4.添加以下几行代码到表格的末尾

''InitializeComponent''方法。

UCOMIConnectionPointContainer pConPtCon =

( UCOMIConnectionPointContainer)this.axWebBrowser1。 GetOcx();

UCOMIConnectionPoint pConPt;

Guid guid = typeof(SHDocVw.DWebBrowserEvents2).GUID;

pConPtCon.FindConnectionPoint(ref guid, out pConPt);

IEEvents e = new IEEvents();

//确保在表单类中声明private int dwCookie但在外面

这种方法

pConPt.Advise(e,out dwCookie);


5.将以下代码行添加到Forms Close的开头

处理程序方法。

UCOMIConnectionPointContainer pConPtCon =

(UCOMIConnectionPointContainer)this.axWebBrowser1。 GetOcx();

UCOMIConnectionPoint pConPt;

Guid guid = typeof(SHDocVw.DWebBrowserEvents2).GUID;

pConPtCon.FindConnectionPoint(ref guid, out pConPt);

pConPt.Unadvise(dwCookie);


URL: http://www.kbcafe.com/iBLOGthere4iM/...20040501150250


谢谢 - 你和问候

Chad

Hi

In vb.net if you add a webbrowser control the windowclosing event does not
fire. I have searched everywhere for a solution rather I get more people
saying I have the same problem.

I found this...Could someone please convert this to VB.NET to give us a
glimmer of hope OR provide a solution.

If u implement axWebBrowser, you''ll find the WindowClosing event doesn''t
fire. This is the work around, which I confirm works.

1. Right below the System.Windows.Forms.Form class add another class
whichderives from SHDocVw.DWebBrowserEvents2. For example:\

public class IEEvents: SHDocVw.DWebBrowserEvents2
{}

2. Save the file and go to class view (View | Class View menu option). Go to
IEEvents class in the tree view and expand it. Keep expanding its children
till you see ''DWebBrowserEvents''. Right click and select ''Add | Implement
interfaces'' menu option.

3. A method for WindowClosing event should be generated by above step. Apply
the ''DispId'' attribute to the method as shown below:

[DispId(0x00000107)]
public void WindowClosing(bool IsChildWindow, ref bool Cancel)
{
//message box to the event handler works
MessageBox.Show("Closing Event", "IE", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}

4. Add the following lines of code to the end of the Forms
''InitializeComponent'' method.

UCOMIConnectionPointContainer pConPtCon =
(UCOMIConnectionPointContainer)this.axWebBrowser1. GetOcx();
UCOMIConnectionPoint pConPt;
Guid guid = typeof(SHDocVw.DWebBrowserEvents2).GUID;
pConPtCon.FindConnectionPoint(ref guid, out pConPt);
IEEvents e = new IEEvents();
//make sure you declare private int dwCookie in the form class but outside
this method
pConPt.Advise(e, out dwCookie);

5. Add the following lines of code to the beginning of the Forms Close
handler method.

UCOMIConnectionPointContainer pConPtCon =
(UCOMIConnectionPointContainer)this.axWebBrowser1. GetOcx();
UCOMIConnectionPoint pConPt;
Guid guid = typeof(SHDocVw.DWebBrowserEvents2).GUID;
pConPtCon.FindConnectionPoint(ref guid, out pConPt);
pConPt.Unadvise(dwCookie);

URL:http://www.kbcafe.com/iBLOGthere4iM/...20040501150250

Thank-you and regards
Chad

推荐答案

Chad写道:
Chad wrote:

Hi


在vb.net中,如果你添加一个webbrowser控件,windowclosing事件不会消耗
。我到处寻找一个解决方案而不是让更多的人

说我有同样的问题。
Hi

In vb.net if you add a webbrowser control the windowclosing event does not
fire. I have searched everywhere for a solution rather I get more people
saying I have the same problem.



我无法使用VB.Net 2005复制您的错误。我将一个

WebBrowser控件拖到窗体中。然后我添加了一个FormClosing事件。当我关闭表单时,

事件正常触发。也许我对这个问题有误解。


你能发一个简短而完整的程序来解释这个问题吗?


Chris

I cannot duplicate your error using VB.Net 2005. I dragged a
WebBrowser control to the form. I then added a FormClosing event. The
event fired normally when I closed the form. Perhaps I am
misunderstanding the problem.

Can you post a short but complete program that illustrates the problem?

Chris


谢谢Chris


我应该更加详细。

如果您使用java脚本访问html页面以关闭表单,则不会通过webbrowser触发

windowclosing事件。它适用于VB6,但

不是VB.NET,这非常烦人。


我为你设置了一个例子,添加代码并点击关闭按钮。


在vb6

添加webbrowser控件和此代码...

Private Sub Form_Load()

WebBrowser1.Navigate" www.aztecenergy.co.nz/close.html"

End Sub


Private Sub WebBrowser1_WindowClosing(ByVal IsChildWindow As Boolean,取消

As Boolean)

MsgBox" WindowClosing Fired"

End Sub


现在在VB.NET中添加webbrowser和这段代码

Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理MyBase。加载

AxWebBrowser1.Navigate(" www.aztecenergy.co.nz/close.html")

结束子


Private Sub AxWebBrowser1_WindowClosing(ByVal sender As Object,ByVal e As

AxSHDocVw.DWebBrowserEvents2_WindowClosingEvent )句柄

AxWebBrowser1.WindowClosing

MessageBox.Show(" WindowClosing Fired")

End Sub


WindowClosing事件未被触发,因此消息框未显示...


为什么以及如何解决这个问题???


Chris Dunaway写道:
Thanks Chris

I should of been more detailed.

If you access a html page with java script to close the form the
windowclosing event is not fired through the webbrowser. It works in VB6 but
not VB.NET which is very annoying.

I have set up an example for you, add the code and click on the close button.

In vb6
Add the webbrowser control and this code...
Private Sub Form_Load()
WebBrowser1.Navigate "www.aztecenergy.co.nz/close.html"
End Sub

Private Sub WebBrowser1_WindowClosing(ByVal IsChildWindow As Boolean, Cancel
As Boolean)
MsgBox "WindowClosing Fired"
End Sub

Now in VB.NET add the webbrowser and this code
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
AxWebBrowser1.Navigate("www.aztecenergy.co.nz/close.html")
End Sub

Private Sub AxWebBrowser1_WindowClosing(ByVal sender As Object, ByVal e As
AxSHDocVw.DWebBrowserEvents2_WindowClosingEvent) Handles
AxWebBrowser1.WindowClosing
MessageBox.Show("WindowClosing Fired")
End Sub

The WindowClosing event is not fired and thus the messagebox is not shown...

Why and how do I fix this???

"Chris Dunaway" wrote:

Chad写道:
Chad wrote:




在vb.net中,如果你添加一个webbrowser控件,windowclosing事件不会消耗。我到处寻找一个解决方案而不是让更多的人

说我有同样的问题。
Hi

In vb.net if you add a webbrowser control the windowclosing event does not
fire. I have searched everywhere for a solution rather I get more people
saying I have the same problem.



我无法使用VB.Net 2005复制您的错误。我将一个

WebBrowser控件拖到窗体中。然后我添加了一个FormClosing事件。当我关闭表单时,

事件正常触发。也许我对这个问题有误解。


你能发一个简短而完整的程序来解释这个问题吗?


Chris


I cannot duplicate your error using VB.Net 2005. I dragged a
WebBrowser control to the form. I then added a FormClosing event. The
event fired normally when I closed the form. Perhaps I am
misunderstanding the problem.

Can you post a short but complete program that illustrates the problem?

Chris


Chad,


我认为你的样品有点混合但是。


2.0 webbrowser中的事件非常非常不如AxWebbrowser中的

。正如Herfried所展示的那样,可以为那些创建

的变通办法。我不知道这个的解决方法。


也许如果没有退回的文件。


Cor


" Chad" < ch ** @ discussion.microsoft.comschreef in bericht

新闻:1F ************************** ******** @ microsof t.com ...
Chad,

I assume that your samples are a little bit mixed up, however.

The events in the 2.0 webbrowser are very very very much inferior to the
ones in the AxWebbrowser. As Herfried ones showed is it possible to create
workarounds for those. I don''t know a workaround for this one.

Maybe if there are no returned documents.

Cor

"Chad" <Ch**@discussions.microsoft.comschreef in bericht
news:1F**********************************@microsof t.com...

谢谢Chris


我应该去过更详细。


如果您使用java脚本访问html页面以关闭表单,则不会通过webbrowser触发

windowclosing事件。它适用于VB6



不是VB.NET,这非常烦人。


我为你设置了一个例子,添加代码,然后单击关闭

按钮。


在vb6

添加webbrowser控件和此代码.. 。

Private Sub Form_Load()

WebBrowser1.Navigate" www.aztecenergy.co.nz/close.html"

End Sub


Private Sub WebBrowser1_WindowClosing(ByVal IsChildWindow作为布尔值,

取消

作为布尔值)

MsgBox" ; WindowClosing被解雇了

End Sub


现在在VB.NET中添加webbrowser和这段代码

Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理MyBase.Load

AxWebBrowser1.Navigate(" www.aztecenergy.co.nz/close.html" ;)

结束子


私人子AxWebBrowser1_WindowClosing(ByVal发件人作为对象,ByVal e

As

A. xSHDocVw.DWebBrowserEvents2_WindowClosingEvent)句柄

AxWebBrowser1.WindowClosing

MessageBox.Show(" WindowClosing Fired")

End Sub


WindowClosing事件未被触发,因此消息框不显示

...


为什么以及如何解决这个问题? ??


" Chris Dunaway"写道:
Thanks Chris

I should of been more detailed.

If you access a html page with java script to close the form the
windowclosing event is not fired through the webbrowser. It works in VB6
but
not VB.NET which is very annoying.

I have set up an example for you, add the code and click on the close
button.

In vb6
Add the webbrowser control and this code...
Private Sub Form_Load()
WebBrowser1.Navigate "www.aztecenergy.co.nz/close.html"
End Sub

Private Sub WebBrowser1_WindowClosing(ByVal IsChildWindow As Boolean,
Cancel
As Boolean)
MsgBox "WindowClosing Fired"
End Sub

Now in VB.NET add the webbrowser and this code
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
AxWebBrowser1.Navigate("www.aztecenergy.co.nz/close.html")
End Sub

Private Sub AxWebBrowser1_WindowClosing(ByVal sender As Object, ByVal e
As
AxSHDocVw.DWebBrowserEvents2_WindowClosingEvent) Handles
AxWebBrowser1.WindowClosing
MessageBox.Show("WindowClosing Fired")
End Sub

The WindowClosing event is not fired and thus the messagebox is not
shown...

Why and how do I fix this???

"Chris Dunaway" wrote:

> Chad写道:
>Chad wrote:




在vb.net中如果你添加一个webbrowser控件,windowclosing事件确实

not

fire。我到处寻找解决方案而不是我得到更多

人们

说我有同样的问题。
Hi

In vb.net if you add a webbrowser control the windowclosing event does
not
fire. I have searched everywhere for a solution rather I get more
people
saying I have the same problem.


我无法使用VB.Net 2005复制您的错误。我将一个
WebBrowser控件拖到表单中。然后我添加了一个FormClosing事件。当我关闭表单时,
事件正常触发。也许我误解了这个问题。

你能发一个简短而完整的程序来解释这个问题吗?

Chris


I cannot duplicate your error using VB.Net 2005. I dragged a
WebBrowser control to the form. I then added a FormClosing event. The
event fired normally when I closed the form. Perhaps I am
misunderstanding the problem.

Can you post a short but complete program that illustrates the problem?

Chris



这篇关于windowclosing没有开火的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆