在Form.cs里面加上这个方法:
protected override void OnClosing(CancelEventArgs e){ DialogResult result = MessageBox.Show("是否确认关闭?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); e.Cancel = result != DialogResult.Yes; base.OnClosing(e);}