vendredi, octobre 14, 2011

c# override closing event of a form

Am using a overide of closing event of the form, for example you can ask if user want to quit :

protected override void OnFormClosing(FormClosingEventArgs e)
{
    base.OnFormClosing(e);

    if (e.CloseReason == CloseReason.WindowsShutDown) return;

    // Confirm user wants to close
    switch (MessageBox.Show(this, "Are you sure you want to close?",  
             "Closing", MessageBoxButtons.YesNo))
    {
    case DialogResult.No:
        e.Cancel = true;
        break;
    default:
        break;
    }        
}

Or just minizing your form by calling Hide(), and activating your systray icon !

Aucun commentaire: