在Designer.cs文件中的委托~~
this.Closing +=new CancelEventHandler(Form1_Closing);
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
// Determine if text has changed in the textbox by comparing to original text.
if (textBox1.Text != strMyOriginalText)
{
// Display a MsgBox asking the user to save changes or abort.
if(MessageBox.Show("Do you want to save changes to your text?", "My Application",
MessageBoxButtons.YesNo) == DialogResult.Yes)
{
// Cancel the Closing event from closing the form.
e.Cancel = true;
// Call method to save file...
}
}
}
vs2005 窗体退出事件
最新推荐文章于 2022-02-18 13:21:17 发布
本文介绍了一种在Windows窗体应用程序中检测文本框内容变更并在用户尝试关闭表单时提示保存更改的方法。通过比较当前文本与原始文本,利用消息框询问用户是否保存更改,若用户选择保存,则取消关闭事件并调用保存文件的方法。
2289

被折叠的 条评论
为什么被折叠?



