0
我面临多窗体应用程序的问题 我有mainForm和几个mdi窗体。 其中一个子窗体(frmDashboardManager)在mainForm外部打开new ownedforms(frmDahboard) 否我想检查frmDahboard是否打开,如果是,则关闭它。 以下是我有:从另一个窗体关闭窗体
Dim fDash As New frmDashboard
fDash = isDashboardOpen(tempDash)
If fDash IsNot Nothing Then
fDash.Close() 'HERE I GET THE ERROR
End If
Private Function isDashboardOpen(ByVal dash As clsDashboard) As frmDashboard
isDashboardOpen = Nothing
Try
'search if Dashboard is already open
For Each fr As frmDashboard In Me.OwnedForms
If fr.My_Dashboard.Id = dash.Id Then
isDashboardOpen = fr
Exit For
End If
Next
Catch ex As Exception
gError.GetAppEx(ex, FORM_NAME & ".isDashboardOpen")
Finally
End Try
End Function
,我得到的是错误: 对象引用不设置到对象的实例。
疯狂的事情是,我检查和isDashboardOpen实际返回一个frmDashboard(也就是为什么执行fDash.Close())。 任何想法?
谢谢
使用'作为新的'是非常非常错误的。它会创建表单的第二个实例,其中一个是您无法看到的。 –