C#程序运行问题

来源:百度知道 编辑:UC知道 时间:2024/06/13 19:54:17
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 学习8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void Form1_Formclosing(object sender,FormClosingEventArgs e)
{
if (MessageBox.Show("确定需要退出吗?", "确定", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
}
else
{
e.Cancel = true;
}
}
}
}
写这个程序主要是为了让他关闭运行程序的时候有个提示,现在关闭的时候没提示是什么原因

用了上面的方法还是不行啊

private void Form1_Formclosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("确定需要退出吗?", "确定", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
}
else
{
e.Cancel = true;
}
}
你的这个事件并没有加入到事件列表中,在构造函数中添加
this.FormClosing+=new FormClosingEventHandler(Form1_Formclosing);

你这个是什么意思啊! 不明白你要干什么,是不是想弄个button点击的时候,提示是不是要退出,点确定,然后就退出?如果是这样的话你就可以直接在
private void button_Click(object sender, EventArgs e)
{
if (MessageBox.Show("确定退出本系统吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK)
{
Application.Exit();
}
}

if (MessageBox.Show("确定需要退出吗?", "确定", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
this.Close();
}

写到 private void button