C# 关闭窗体

来源:百度知道 编辑:UC知道 时间:2024/05/23 13:27:52
关闭当前窗体(就是点击窗体最右上角的X)
弹出MessageBox,询问是否真的要关闭?
点是,关闭当前窗体,
点否,放弃操作,不关闭

楼上的是vs2008开发
如果是vs2005开发
如何做到在点击一个Winform的关闭按钮时,不是直接退出程序,而是弹出一个对话框提示用户是否退出呢?只要添加Form的FormClosing事件就可以了。

代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void OnClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("确实要退出吗", "hello", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
e.Cancel = true;
}
}
}

你要问什么。。。

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("??", "??", MessageBoxButtons.OKCancel) == DialogResult.OK)
Application.E