How to prevent or block closing a WinForms window?

后端 未结 8 706
情书的邮戳
情书的邮戳 2020-12-01 04:01

How can I prevent window closing by showing a MessageBox? (Technology:WinForms with C#)

When the close event occurs I want the

8条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 04:56

    For prevent or block the form closing in particular situation you can use this strategy:

    private void MyForm_FormClosing(object sender, FormClosingEventArgs e)
    {
    
        if (FLAG_CONDITION == true)
        {
            MessageBox.Show("To exit save the change!!");
            e.Cancel = true;
        }
    
    }
    

提交回复
热议问题