在WPF中用户关闭程序前弹出确认对话框!
在Colsing事件中添加如下代码
private async void MetroWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (MessageBox.Show("您确定退出?", "警告", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
//释放网络资源
TCPRobot.GetInstance().Dispose();
Application.Current.Shutdown();//关闭
}
else
{
e.Cancel = true;
}
}
在WPF应用程序中,为确保用户在关闭程序前进行确认操作,可以在Closing事件中添加代码,通过MessageBox显示确认对话框。如果用户选择'是',则释放网络资源并关闭应用;若选择'否',则取消关闭操作。
644

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



