Form.Load事件不触发,表单显示 [英] Form.Load event not firing, form showing

查看:259
本文介绍了Form.Load事件不触发,表单显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我担心我的代码有一些明显的错误,但是我遇到了一个情况,当我创建并显示我的事件时,$ code> Form.Load 事件不会触发形成。



表单不是子类的(因为我在某些搜索中看到一些问题),当我逐步浏览代码时,我没有收到任何错误调试器。



我在IDE创建的表单加载功能上设置了一个断点(它具有处理MyBase.Load 签名后缀),但断点永远不会被覆盖,并且表单确实显示和工作。



表单在构造函数中传递三个参数,但 IntializeComponent()函数在其他任何操作完成之前被调用。



代码:


$ b $公共子新建(ByVal argA As Object,ByVal argB As Object,ByVal mode As FormMode)

'Windows窗体设计器需要此调用。
InitializeComponent()

'其他代码在这里,
'没有错误生成
'

End Sub

表单加载函数如下所示(但是事实上并没有被激活)。



代码:

  Private Sub frmInstrumentEditor_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)处理MyBase.Load 
如果不是argA是Nothing然后'argA设置在构造函数
'操作使用argA
结束如果
结束Sub
$ / pre

我可能会添加我正在使用一些数据绑定与一些控件和 argA 对象,但是如果这是一个错误,我以为我会看到这个(我有CLR Execpetions设置设置为在调试器中的Thown>例外窗口)



任何想法为什么这样可能会发生?

解决方案

我刚刚有一个类似的问题(它在显示事件,而不是加载,但根本原因是一样的)。原因被隐藏在其中一个祖先 - 有一个未处理的 NullReferenceException 抛出,这个异常以某种方式静音。


$ b $我在F11进行了大量调试后发现。



但是...在写这个答案的时候,我发现这个 post on SO



只需添加您的 Main()方法中的Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException)



如果您使用的是64位计算机,那么它将为您提供解决方案(在我的情况下也是如此)。


I fear that there is something obviously wrong with my code, but I have come across a situation where the Form.Load event is not firing when I create and show my form.

The form is not subclassed (as I've seen some problems with that in some searches), and I am not getting any errors thrown when I step through the code in the debugger.

I have a break point set on the IDE-created form load function (which does have the Handles MyBase.Load signature suffix) but the breakpoint is never reached and the form does display and work.

The form is passed three arguments in the constructor but the IntializeComponent() function is called before anything else is done.

Code:

Public Sub New(ByVal argA As Object, ByVal argB As Object, ByVal mode As FormMode)

    ' This call is required by the Windows Form Designer.
    InitializeComponent()

    ' Other code here,
    ' No errors generated
    '

End Sub

The form load function is as follows, (but this is never actually executed as the event is not fired).

Code:

Private Sub frmInstrumentEditor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    If Not argA Is Nothing Then ' argA set in constructor
          ' Operations using argA
    End If
End Sub

I might add I am using some databinding with some controls and the argA object, but if this was producing an error I thought I would have seen this (I have CLR Execpetions settings set to Thown in the debugger > exceptions window)

Any ideas why this might be occurring?

解决方案

I just had a similar issue (it was in Shown event, not Load, but the root cause is the same). The reason was hidden deep in one of the ancestors - there was an unhandled NullReferenceException thrown and this exception was somehow "muted".

I found it after extensive debugging with F11.

But... when writing this answer I found this post on SO

Just add Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException) in your Main() method.

If you're using a 64-bit machine, it provides you with the solution (it worked in my case, too).

这篇关于Form.Load事件不触发,表单显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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