我目前遇到了Windows窗体应用程序Closing的问题。 我在主窗体中有多个表单。如果我关闭主窗体,而主窗体中的一个窗体是stil初始化应用程序崩溃Close()因为createHandler()仍在运行。
我已经在其中一个子表单中解决了这个问题,为Load()添加了一个布尔值,并检查boolean是否为true。例如:
Private Sub frm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ini = True
// loading components etc.
ini = False
End Sub
Private Sub frm_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
If e.KeyData = Keys.Escape Then
If (not ini)
Close()
End If
End If
现在我在主要表单中有simulair问题。
Dim Childs = (From rec In Me.MdiChildren).ToList
For Each Child In Childs
Child.Close()
Next
在我关闭之前,是否要验证childForm是否已初始化? 类似于:Child.IsInit()