从另一个表单关闭表单

时间:2012-10-03 11:22:06

标签: vb.net winforms

我遇到了多窗体应用程序的问题 我有mainForm和几个mdiForms。 其中一个子窗体(frmDashboardManager)是在mainForm之外打开的新的ownforms(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()的原因)。 有什么想法吗?

由于

1 个答案:

答案 0 :(得分:0)

我刚发现错误。

我在frmDashboard中处理了两次用户控件。 我纠正了这一切,一切正常。

感谢您的时间。

相关问题