Click here to Skip to main content
15,878,048 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Is there a way to detect when an application exits if I am using Sub Main and ApplicationContext? I haven't been able to find anything yet, so I though I would ask y'all.

Dave Kreskowiak 30-Oct-10 22:48pm    
You're going to have to show your code in Sub Main. What you're doing isn't standard and anyone who suggests something is mearly guessing at what your setup is like.
Matchlighter 5-Nov-10 20:23pm    
I decided to go with a hidden master form. Thanks for your help :)

1 solution

You Can Find it for VB.Net:cool:
This Is the Form Closing event automatically raised when form closes

Private Sub Form1_Closing(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
      ' Determine if text has changed in the textbox by comparing to original text.
      If textBox1.Text <> strMyOriginalText Then
         ' Display a MsgBox asking the user to save changes or abort.
         If MessageBox.Show("Do you want to save changes to your text?", "My Application", MessageBoxButtons.YesNo) = DialogResult.Yes Then
            ' Cancel the Closing event from closing the form.
            e.Cancel = True
         End If ' Call method to save file...
      End If
   End Sub 'Form1_Closing
End Class 'Form1
Share this answer
Matchlighter 30-Oct-10 0:35am    
There is no form. It uses Sub Main and ApplicationContext.
Be Yourself 1-Nov-10 0:55am    
You can Use return() to return from the main block from whatever point U like.
Otherwise in VB you can use Exit Sub..
Moreover your question is not clear Please Post some coding idea what U are trying to do.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900