(1)直接设置
窗口样式中的ControlBox选为False就可以去掉右上角的叉
(2)重写关闭事件
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- DialogResult result;
- result = MessageBox.Show("确定退出吗?", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
- if (result == DialogResult.OK)
- {
- Application.ExitThread();
- }
- else
- {
- e.Cancel = true;
- }
- }