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())。 任何想法?
謝謝
使用'作爲新的'是非常非常錯誤的。它會創建表單的第二個實例,其中一個是您無法看到的。 –