Question Form Closing Help

TripleD

New member
Joined
Jul 31, 2012
Messages
4
Programming Experience
Beginner
Hi,

I'm trying to handle form closing, so I've created the code below.

VB.NET:
Private Sub frmConfig_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        If MessageBox.Show("Are you sure you want to exit?", "App Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
            e.Cancel = False
            frmMain.Show()
            myWriter.Close()
            Exit Sub
        Else
            e.Cancel = True
        End If
    End Sub

The aim was I want to be able to control when a user clicks on the Red X button, which it does, but in my form I also have a 'Save' Button (btnSave). I don't want the MessageBox to show if the 'Save' button is clicked.
I'm not sure how to go about achieving this, any pointers would be great.
 
help said:
The Closing event is obsolete in the .NET Framework version 2.0; use the FormClosing event instead.
FormClosing event has CloseReason event info that can be used. There's no correlation between saving data and closing an app as such, but if you have some sort of 'save & exit' functionality you can distinguish between UserClosing and ApplicationExitCall and other reasons.
 
Back
Top