View the OnClosing event for the form.
Here is an excerpt from this link actually checks for a change in the text box and suggests saving:
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (textBox1.Text != strMyOriginalText)
{
if(MessageBox.Show("Do you want to save changes to your text?", "My Application",
MessageBoxButtons.YesNo) == DialogResult.Yes)
{
e.Cancel = true;
}
}
}
You can change the text to suit your needs, and then, I think, you can switch DialogResult.Yesbased DialogResult.Noon your text.
Here are some modified codes for you:
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if(MessageBox.Show("Are you sure you want to quit?", "My Application", MessageBoxButtons.YesNo) == DialogResult.No)
{
e.Cancel = true;
}
}