views:

92

answers:

3

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
Mmm, wouldn't OnClosed be more appropriate?
R. Bemrose
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
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
+4  A: 

I believe you are looking for the Application.Exit method.

Andrew Hare
+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