The contents of a FormClosing event handler should take this general form:That's basically it. As has already been said, the FormClosing event is raised because the form is closing, so there's no need for you to do anything else to make it close. You only have to do something if you don't want the form to close, i.e. set e.Cancel to True. You can do whatever else you like in there as well but NOTHING else related to closing or not closing the form. To be more specific to your case:Code:If ShouldTheFormStayOpen Then e.Cancel = True End IfThat's basically it.Code:Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing If TextBox1.TextLength > 0 Then Select Case MessageBox.Show("Would you like to save your changes?", "Changes Pending", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) Case DialogResult.Yes 'Save the changes and let the form close. Button1.PerformClick() Case DialogResult.No 'Do nothing. Case DialogResult.Cancel 'Don't let the form close. e.Cancel = True End Select End If End Sub




Reply With Quote
