gpt4 book ai didi

c# - 按 "X"按钮时允许取消

转载 作者:行者123 更新时间:2023-11-30 18:57:12 25 4
gpt4 key购买 nike

当用户在主窗口中按下“X”时,我会出现这个对话框:

 -- Save Changes --------------------------
| |
| Do you want to save changes? |
| |
| |
| |Don't Save| |Cance| |Save| |
|__________________________________________|

我在实现“取消”按钮时遇到问题。我不知道如何告诉主窗口在用户点击取消后不要关闭。我通过窗口的“关闭”命令/方法提示用户使用此对话框。

最佳答案

在关闭事件中,需要将事件属性Cancel设置为true。

    void DataWindow_Closing(object sender, CancelEventArgs e)
{
MessageBox.Show("Closing called");

// If data is dirty, notify user and ask for a response
if (this.isDataDirty)
{
string msg = "Data is dirty. Close without saving?";
MessageBoxResult result =
MessageBox.Show(
msg,
"Data App",
MessageBoxButton.YesNo,
MessageBoxImage.Warning);
if (result == MessageBoxResult.No)
{
// If user doesn't want to close, cancel closure
e.Cancel = true;
}
}
}

关于c# - 按 "X"按钮时允许取消,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11001569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com