在关闭Winform时,弹出确认退出提示框

添加人:iyond五级(2392分)   添加时间:2008-05-12    阅读次数:434  收藏此教程

如何做到在点击一个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;
        }
    }
}

1页 第1上一页1下一页
相关的教程: 确认退出 FormClosing
收藏此教程

当前平均分: -1.4(8 次打分)

-5-4-3-2-1012345
评论主题
您的大名
您的评论
验证码 点击换一个验证码
知识库搜索: