我正在研究WPF应用程序。其中一个Windows的IsCancel=true
有一个名为“取消”的按钮。当用户单击取消或按下ESCAPE
键时,我需要显示带有是/否的消息框。如果用户单击是,窗口应该继续关闭,但如果用户单击否,它不应该关闭窗体,但在窗口打开的情况下继续常规操作。我该怎么做?请帮忙。提前致谢。WPF取消按钮
Q
WPF取消按钮
2
A
回答
3
这将帮助你
void Window_Closing(object sender, CancelEventArgs e)
{
MessageBoxResult result = MessageBox.Show(
"msg",
"title",
MessageBoxButton.YesNo,
MessageBoxImage.Warning);
if (result == MessageBoxResult.No)
{
// If user doesn't want to close, cancel closure
e.Cancel = true;
}
}
3
你可以在WindowClosing
处理它。
看一看here。有一个非常接近你的例子。
1
var Ok = MessageBox.Show("Are you want to Close", "WPF Application", MessageBoxButton.YesNo, MessageBoxImage.Information);
if (Ok == MessageBoxResult.Yes)
{
this.Close();
}
else
{
}
1
打开一个消息框,并宣读结果像这样:
DialogResult result = MessageBox.Show(
"Text",
"Title",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
//The user clicked 'Yes'
}
else if (result == DialogResult.No)
{
//The user clicked 'No'
}
else
{
//If the user somehow didn't click 'Yes' or 'No'
}
相关问题
- 1. WPF:取消按钮动画
- 2. 取消按钮
- 3. iPhone取消按钮
- 4. jqTransform取消按钮
- 5. JDialog取消按钮
- 6. 如何“取消”按钮按?
- 7. Ios:取消高亮取消按钮
- 8. Javascript提示取消按钮不“取消”
- 9. Bootstrap Validator.js和取消按钮
- 10. jeditable取消按钮回调?
- 11. UISearchBar取消按钮Xcode 4.3?
- 12. Silverlight关闭/取消按钮
- 13. Laravel表单按钮取消
- 14. 点击取消按钮showInputDialogue
- 15. UISearchcontroller取消按钮代理
- 16. UIAlertView无取消按钮?
- 17. FBDialog取消按钮回调
- 18. 取消选项组按钮
- 19. Powershell&取消按钮或ESC
- 20. Android:DatePickerdialog与取消按钮
- 21. IAP iOS UIAlertView取消按钮
- 22. 倒计时取消按钮
- 23. 取消按钮使用MBProgressView
- 24. 的UISearchBar取消按钮
- 25. 启用通过WPF命令模式提交/取消按钮
- 26. 取消异步方法的按钮(wpf - databinding命令)
- 27. 如何在按下取消按钮时取消部分视图
- 28. 按取消按钮不收回
- 29. 如何按下按钮取消超时?
- 30. remove从本地通知取消按钮或覆盖取消按钮功能
那么这就是问题!怎么做'不'? – 2013-04-22 08:40:32
在NO部分是否使用'e.Cancel = True'。 – 2013-04-22 08:42:16
只需将空白选项保留为空。 – 2013-04-22 08:44:23