需要使用到窗体的 FormClosing 事件
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e) {DialogResult dialogResult = MessageBox.Show("是否确认关闭窗口", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);if (dialogResult != DialogResult.OK){//取消当前关闭操作e.Cancel = true;} }