点击按钮询问是否退出,点击是就结束窗体,点击否就什么也不做 winform 1030

237 阅读1分钟
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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

        private void btnExit_Click(object sender, EventArgs e)
        {
            // 弹窗提示
           DialogResult result = MessageBox.Show("确定要退出吗?","退出询问",MessageBoxButtons.YesNo, MessageBoxIcon.Information);
        
            // 判断用户的操作
            if(result == DialogResult.Yes){
                // 关闭窗体
                this.Close();
            }
        
        }
    }
}