关闭窗体前触发事件

有时有关闭窗体前需要触发事件,如退出前自动备份、确认退出等

在窗体标记里添加Closing事件: Closing="Window_Closing"

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
MessageBoxResult key
= MessageBox.Show(
"Are you sure you want to quit",
"Confirm",
MessageBoxButton.YesNo,
MessageBoxImage.Question,
MessageBoxResult.No);
e.Cancel
= (key == MessageBoxResult.No);
}
posted @ 2011-02-17 21:43  Laro  阅读(375)  评论(0编辑  收藏  举报