I’m trying to detect whether or not the user have save their work before closing the program. I’ve tried the below coding:
void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
MessageBox.Show("Unsave Work");
}
But it does not work. Nothing happen when I close the program.
There are two primary ways to add an EventHandler in .Net.
You can use the designer to add it.
Or you can add it in code