思路:
设置一个bool变量flag
在有改动的时候置为true
然后在Closing事件中根据flag的值作出动作
设置一个bool变量flag
在有改动的时候置为true
然后在Closing事件中根据flag的值作出动作
解决方案 »
- C#和.net框架打包问题
- 制作安装程序时,如何制作数据库安装包?
- asp.net gridview的问题
- 简单多数据库链接问题 ,还未解决 ,问题再问
- help me, help me! 关于大数据COPY ,有谁了解 bluk insert
- HttpWebRequest 可不可以请求100行,而不是整个一页
- 有谁知道那里有关于Duwamish7的代码剖析的文档。。。。
- 请问水晶报表导入到Excel时,如何使导出的Excel具有表格框架,谢谢!
- net_lover(孟子E章)高人请进,分请笑纳~~~
- C#form中多页打印,如何实现选择其中的一些页打印出来?
- 各位老大/高手:配置文件应该放在什么目录下
- 请问在那里有<<C#入门经典>>这本书的电子版下载啊?
...
private void OnClosing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (MessageBox.Show("Are you sure", "Terminate the Application",
MessageBoxButtons.YesNo) == DialogResult.No)
e.Cancel = true; // default is false, assign to true to stop the termination process
}
可以在TextChange里面,如果改变量为false,则设置为true;
在保存的方法里面,保存完之后设置为false;
退出的时候判断,如果为true,就说明要保存,那就弹出一个MessageBox,点yes保存,no 退出
/// <summary>
/// 文本变化事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
if(!flag) flag = true;
} /// <summary>
/// 退出事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if(flag) MessageBox.Show("gaga");
}
/// <summary>
/// 保存事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, System.EventArgs e)
{
flag = false;
}
在窗体的ONCLOSING事件添加如下代码:
if(dirty)
{
if(MessageBox.Show("文件尚未保存.是否保存所做的修改?","提示",
MessageBoxButtons.YesNo,MessageBoxIcon.Information)==DialogResult.Yes)
menuItemSave_Click(参数列表); }