C#关闭窗口代码

if (MessageBox.Show("请您确认是否退出(Y/N)", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
            {
                try
                {
                    this.Dispose();
                    this.Close();
                }
                catch (System.Exception error)
                {//WinIO卸载失败异常
                    MessageBox.Show(error.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            else
            {
                return;
            }

原文地址:https://www.cnblogs.com/zhayunjia/p/3751665.html