Calling Application.Exit()
will actually attempt to close all your forms, and because your FormClosing
is hard coded to be cancelled, then it cannot complete the task.
One option with your current structure would be to create an AllowClose
flag. This could be a property of the Form, or it could be a global static value.
For example:
//in your form
public bool AllowClose {get;set;}
private void Ana_FormClosing(object sender, FormClosingEventArgs e)
{
if(!AllowClose)
{
e.Cancel = true;
this.Hide();
}
}
//in your context menu event
private void kapatToolStripMenuItem_Click(object sender, EventArgs e) //Close
{
DialogResult ext;
ext = MessageBox.Show("Çıkmak İstediğinizden Emin misiniz?", "Onay", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (ext == DialogResult.Yes)
{
this.AllowClose = true;
Application.Exit();
}
}