Asking for confirmation when “X” button is clicked

后端 未结 5 1628
时光说笑
时光说笑 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:30

    just take it simple

    protected override void OnFormClosing(FormClosingEventArgs e)
            {            
                base.OnFormClosing(e);
                if (PreClosingConfirmation() == System.Windows.Forms.DialogResult.Yes)
                {
                    Dispose(true);
                    Application.Exit();
                }
                else
                {
                    e.Cancel = true;
                }
            }
    
            private DialogResult PreClosingConfirmation()
            {
                DialogResult res = System.Windows.Forms.MessageBox.Show(" Do you want to quit?          ", "Quit...", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                return res;
            }
    

提交回复
热议问题