【发布时间】:2012-12-04 10:39:20
【问题描述】:
我的 Quit 方法中目前有以下代码:
public void QuitApplication(FormClosingEventArgs a, bool b)
{
bool c = Properties.App.Default.AskToExit, d = Properties.App.Default.AskToSave;
if (!b)
{
if (!c && !d)
{
}
else if (!c)
{
if (YesNoMessageBox("Save Before Quit?", "Would you like to save your settings before you Quit?") == DialogResult.Yes)
{
_debug("Settings Saved");
//Properties.App.Default.Save();
//Properties.Settings.Default.Save();
}
}
else if (!d)
{
if (YesNoMessageBox("Really Quit?", "Are you sure you want to quit?") == DialogResult.No)
{
a.Cancel = true;
}
}
else
{
if (YesNoMessageBox("Really Quit?", "Are you sure you want to quit?") == DialogResult.Yes)
{
if (YesNoMessageBox("Save Before Quit?", "Would you like to save your settings before you Quit?") == DialogResult.Yes)
{
_debug("Settings Saved");
//Properties.App.Default.Save();
//Properties.Settings.Default.Save();
}
}
else
{
a.Cancel = true;
}
}
}
}
这用于检查用户是否想要退出并在他们想要时保存。但是,我有两个选项可以设置为在调用此方法时忽略要求保存或要求退出。我想到的比较这些的唯一方法是上面的,我相信你可以做到,所以重复次数要少得多。 (保存方式已被注释掉,因为应用仍在开发中,设置文件尚未完成)。
谁能帮忙?
【问题讨论】:
-
在退出应用程序之前问这么多事情真的很烦人
-
if(!c && !d) 应该怎么做?
-
a、b、c和d真的有用吗?如果我是一名新开发人员,正在查看您的代码,这到底是什么意思? -
以及@Habib 所说的;这会非常烦人(也是我曾经犯过的一个错误)
-
它们并不是真正有用的名称,不,但没有其他人会接受此代码,我有点强迫症。 C 和 D 是特定设置选项的值。 @habib 是的,我知道,这就是为什么我添加了删除它们的选项。