At the event of FormClosing add the following code
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (DialogResult.No == MessageBox.Show("are you sure to exit", "Alert", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk))
{
e.Cancel = true;
}
}