我正在研究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. 啓用按鈕選中/取消WPF
- 3. 取消按鈕
- 4. JDialog取消按鈕
- 5. jqTransform取消按鈕
- 6. WKInterfaceController取消按鈕
- 7. iPhone取消按鈕
- 8. 如何「取消」按鈕按?
- 9. UISearchController關閉取消按鈕後取消按鈕
- 10. Ios:取消高亮取消按鈕
- 11. Javascript提示取消按鈕不「取消」
- 12. Android:DatePickerdialog與取消按鈕
- 13. 取消showinputdialogbox中的按鈕
- 14. UISearchBar裏面取消按鈕
- 15. UISearchcontroller取消按鈕代理
- 16. jeditable取消按鈕回調?
- 17. UISearchbar上的取消按鈕
- 18. 提交按鈕取消
- 19. jQuery:slideUp.delay.slideDown - 用按鈕取消?
- 20. Laravel表單按鈕取消
- 21. FBDialog取消按鈕回調
- 22. UIAlertView無取消按鈕?
- 23. IAP iOS UIAlertView取消按鈕
- 24. 取消按鈕HTML jQuery
- 25. 取消按鈕使用MBProgressView
- 26. Bootstrap Validator.js和取消按鈕
- 27. 取消選項組按鈕
- 28. showBluetoothAccessoryPickerWithNameFilter:完成:取消按鈕
- 29. Powershell&取消按鈕或ESC
- 30. UISearchBar取消按鈕Xcode 4.3?
那麼這就是問題!怎麼做'不'? – 2013-04-22 08:40:32
在NO部分是否使用'e.Cancel = True'。 – 2013-04-22 08:42:16
只需將空白選項保留爲空。 – 2013-04-22 08:44:23