Asking for confirmation when “X” button is clicked

后端 未结 5 1659
时光说笑
时光说笑 2021-01-01 23:50

The problem is that the messagebox with \"sure you wanna close?\" does pop up, but when I click \"no\", it still proceeds to close the program. Any suggestions? Here\'s my c

5条回答
  •  孤独总比滥情好
    2021-01-02 00:37

    The question is now old but this way is more simple and short, and I think it can be useful to those who arrive on this page:

    protected override void OnFormClosing(FormClosingEventArgs e)
    {
        if (MessageBox.Show("Are you sure that you would like to cancel the installer?", "Cancel Installer", MessageBoxButtons.YesNo) == DialogResult.No)
        {
            e.Cancel = true;
        }
    }
    

    and use elsewhere this.Close() rather than a function.

提交回复
热议问题