You can listen to the Form's Closing event, where you can display a MessageBox as show below:
using System.ComponentModel;
private void Form1_Closing( object sender, CancelEventArgs e )
{
string text = "Do you want to close the application?";
string caption = "Close Application";
if ( MessageBox.Show( text, caption, MessageBoxButtons.YesNo )
== DialogResult.No )
e.Cancel = true;
}
Contributed from George Shepherd's Windows Forms FAQ