本文介绍了windowclosing没有开火的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 嗨 在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 谢谢 - 你和问候 ChadHiIn vb.net if you add a webbrowser control the windowclosing event does notfire. I have searched everywhere for a solution rather I get more peoplesaying I have the same problem.I found this...Could someone please convert this to VB.NET to give us aglimmer of hope OR provide a solution.If u implement axWebBrowser, you''ll find the WindowClosing event doesn''tfire. This is the work around, which I confirm works.1. Right below the System.Windows.Forms.Form class add another classwhichderives 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 toIEEvents class in the tree view and expand it. Keep expanding its childrentill you see ''DWebBrowserEvents''. Right click and select ''Add | Implementinterfaces'' menu option.3. A method for WindowClosing event should be generated by above step. Applythe ''DispId'' attribute to the method as shown below:[DispId(0x00000107)]public void WindowClosing(bool IsChildWindow, ref bool Cancel){//message box to the event handler worksMessageBox.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 outsidethis methodpConPt.Advise(e, out dwCookie);5. Add the following lines of code to the beginning of the Forms Closehandler 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/...20040501150250Thank-you and regardsChad推荐答案 我无法使用VB.Net 2005复制您的错误。我将一个 WebBrowser控件拖到窗体中。然后我添加了一个FormClosing事件。当我关闭表单时, 事件正常触发。也许我对这个问题有误解。 你能发一个简短而完整的程序来解释这个问题吗? ChrisI cannot duplicate your error using VB.Net 2005. I dragged aWebBrowser control to the form. I then added a FormClosing event. Theevent fired normally when I closed the form. Perhaps I ammisunderstanding the problem.Can you post a short but complete program that illustrates the problem?Chris 我无法使用VB.Net 2005复制您的错误。我将一个 WebBrowser控件拖到窗体中。然后我添加了一个FormClosing事件。当我关闭表单时, 事件正常触发。也许我对这个问题有误解。 你能发一个简短而完整的程序来解释这个问题吗? ChrisI cannot duplicate your error using VB.Net 2005. I dragged aWebBrowser control to the form. I then added a FormClosing event. Theevent fired normally when I closed the form. Perhaps I ammisunderstanding the problem.Can you post a short but complete program that illustrates the problem?Chris 我无法使用VB.Net 2005复制您的错误。我将一个 WebBrowser控件拖到表单中。然后我添加了一个FormClosing事件。当我关闭表单时,事件正常触发。也许我误解了这个问题。 你能发一个简短而完整的程序来解释这个问题吗? Chris I cannot duplicate your error using VB.Net 2005. I dragged aWebBrowser control to the form. I then added a FormClosing event. Theevent fired normally when I closed the form. Perhaps I ammisunderstanding the problem.Can you post a short but complete program that illustrates the problem?Chris 这篇关于windowclosing没有开火的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-23 13:02