当第二张表格关闭时关闭应用程序

时间:2014-02-11 15:36:56

标签: vb.net visual-studio

如果关闭第二个表单,我已经全神贯注地想要关闭程序了

如果第二个表单可见,我有boolean设置为True,但是当frmCourses.visible检查结束时,我在调试模式An unhandled exception of type 'System.InvalidOperationException' occurred in HomeWork Helper.exe

中收到错误
If Ready Then
        If frmCourses.Visible = False Then
            Application.Exit()
        End If
End if

1 个答案:

答案 0 :(得分:1)

在第二个表单中,为Form2_FormClosed

创建一个方法

将添加此代码:

Private Sub Form2_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed

End Sub

在Sub中,添加Application.Exit()

结果(带注释):

Private Sub Form2_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
    'Closes the Application if the 2nd Form is Closed
    Application.Exit()
End Sub