Alex Gordon
Alex Gordon

Reputation: 60691

How can I close the application when any form is closed?

I have multiple forms in my VB.NET application. How do I make it so that any form I close will terminate the application?

Upvotes: 2

Views: 451

Answers (3)

JaredPar
JaredPar

Reputation: 754525

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

Upvotes: 3

TheTXI
TheTXI

Reputation: 37875

You could probably put your Application.Exit() call in the OnClosed method of the forms.

Upvotes: 3

Andrew Hare
Andrew Hare

Reputation: 351456

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

Upvotes: 4

Related Questions