I have multiple forms in my VB.NET application. How do I make it so that any form I close will terminate the application?
+3
A:
You could probably put your Application.Exit()
call in the OnClosed
method of the forms.
TheTXI
2009-06-08 20:03:23
Mmm, wouldn't OnClosed be more appropriate?
R. Bemrose
2009-06-08 20:31:39
R. Bemrose: Probably. OnClosing was the only event that I could remember off the top of my head. I don't spend nearly enough time in WinForms.
TheTXI
2009-06-08 20:34:11
I don't either, I just remember that onClosing is when you can cancel a close, meaning that the form is still around and can be accessed. I also can't remember if it's OnClose or OnClosed.
R. Bemrose
2009-06-08 20:37:48
+2
A:
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
Public MustInherit Class MyForm
Inherits Form
Protected Overrides Sub OnClose(args As EventArgs)
Application.Exit()
End Sub
End Class
JaredPar
2009-06-09 05:13:32