点击取消关闭窗口,如何让他不关闭,并且窗口内容(如筛选后的dataset)不变呢? 如题? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1)设置窗体的ControlBox为false,彻底拒绝关闭按钮2)在Closing事件中 private void Form1_FormClosing(object sender, FormClosingEventArgs e) { e.Cancel = true; } private void frmMain_FormClosed_1(object sender, FormClosedEventArgs e) { if(MessageBox.Show("确定要退出嘛?", "退出确认", MessageBoxButtons.OKCancel,MessageBoxIcon.Information)==DialogResult.OK) { Application.Exit(); } else { frmMain frmmain = new frmMain(); frmmain.Show(); } }我本来是这样的,但是我在frmMain中嵌入了datagradview搜索后,我搜索了内容后,再点击关闭窗口点击取消,也就是跳到else,但是它变成新的frmMain了,我刚才搜索的内容没了,如何才能保留我刚才datagradview中的内容呢? 用Closing事件,不要用Closed事件代码见2楼的 private void Form1_FormClosing(object sender, FormClosingEventArgs e){ if (MessageBox.Show("确定要退出嘛?", "退出确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) != DialogResult.OK) { e.Cancel = true; }} FormClosed就是Form已经关闭后做的事情.所以需要改成FormClosing事件.支持2,4,6楼. 我的做法跟6楼的一样,都是在closing事件时加个判断是否关闭窗口 else后什么也不做不就可以了吗. vs2012 创建SQL Serve 数据库的一个问题,急求 关于选用数据存储方式的探讨 高手来C# 可以解释一下以下句语的意思吗 C# GetField 的问题 那位有改变LISTVIEW中的标题的高度与样式和背景色的示例代码,我在CODEPROJECT中下载的都是用的是WINDOWS的API作的,如User32.Dll,有没 ASP.NET中如何让客户发图片到数据库? 求教一个关于C#的问题 RDLC报表传参问题 大家帮我一下!我不知道怎么开始呀!我都装好.NET了! 赚分喽~~ ConfigurationManager 在ASP.Net中怎么取
2)在Closing事件中
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
}
{
if(MessageBox.Show("确定要退出嘛?", "退出确认", MessageBoxButtons.OKCancel,MessageBoxIcon.Information)==DialogResult.OK)
{
Application.Exit();
}
else
{
frmMain frmmain = new frmMain();
frmmain.Show();
}
}
我本来是这样的,但是我在frmMain中嵌入了datagradview搜索后,我搜索了内容后,再点击关闭窗口
点击取消,也就是跳到else,但是它变成新的frmMain了,我刚才搜索的内容没了,如何才能保留我
刚才datagradview中的内容呢?
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("确定要退出嘛?", "退出确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) != DialogResult.OK)
{
e.Cancel = true;
}
}