How to prevent or block closing a WinForms window?

后端 未结 8 733
情书的邮戳
情书的邮戳 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:34

    A special twist might be to always prevent just the user closing the form:

    private void Frm_FormClosing(object sender, FormClosingEventArgs e)
    {
        e.Cancel = (e.CloseReason == CloseReason.UserClosing); 
        // disable user closing the form, but no one else
    }
    

提交回复
热议问题