I have multiple forms in my VB.NET application. How do I make it so that any form I close will terminate the application?
我的VB.NET应用程序中有多个表单。如何制作以便我关闭的任何表格都会终止申请?
3 个解决方案
#2
You could probably put your Application.Exit()
call in the OnClosed
method of the forms.
您可以将Application.Exit()调用放在窗体的OnClosed方法中。
#3
The easiest way is to create a base class Form from which all of your Forms inherit. In that particular class you can override the OnClosed method and call Application.Exit to quit the program. Now the closing of any form in your application which derives from this Form, will cause the application to Exit
最简单的方法是创建一个基类Form,从中继承所有表单。在该特定类中,您可以覆盖OnClosed方法并调用Application.Exit以退出程序。现在,在您的应用程序中关闭源自此表单的任何表单将导致应用程序退出
Public MustInherit Class MyForm
Inherits Form
Protected Overrides Sub OnClose(args As EventArgs)
Application.Exit()
End Sub
End Class
#1
I believe you are looking for the Application.Exit
method.
我相信您正在寻找Application.Exit方法。
#2
You could probably put your Application.Exit()
call in the OnClosed
method of the forms.
您可以将Application.Exit()调用放在窗体的OnClosed方法中。
#3
The easiest way is to create a base class Form from which all of your Forms inherit. In that particular class you can override the OnClosed method and call Application.Exit to quit the program. Now the closing of any form in your application which derives from this Form, will cause the application to Exit
最简单的方法是创建一个基类Form,从中继承所有表单。在该特定类中,您可以覆盖OnClosed方法并调用Application.Exit以退出程序。现在,在您的应用程序中关闭源自此表单的任何表单将导致应用程序退出
Public MustInherit Class MyForm
Inherits Form
Protected Overrides Sub OnClose(args As EventArgs)
Application.Exit()
End Sub
End Class