在form窗体“属性”里打开“事件”找到“FormClosing”并双击打开“FormClosing”的代码区写入以下代码:
private void Form1_FormClosing_1(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("是否关闭窗体", "确认", MessageBoxButtons.OKCancel,
MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Cancel)
e.Cancel = true;
}