关闭消息框上的表单回答问题
我正在尝试使用此代码来关闭消息框的特定答案上的表单。我不断收到一条错误消息,指出 Yes
和 No
都不属于 DialogResult::
。我基本上直接从 MS 网站复制了这段代码,所以我不知道出了什么问题。帮助?
private: System::Void Form1_FormClosing(System::Object^ sender, System::Windows::Forms::FormClosingEventArgs^ e) {
if(!watchdog->Checked)
{
if((MessageBox::Show("CAN Watchdog is currently OFF. If you exit with these settings, the SENSOWheel will still be engaged. To prevent this, please enable CAN Watchdog before closing. Would you still like to quit?", "Watchdog Warning", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == DialogResult::No))
{
return;
}
else
{
close_Click(this, e);
}
}
}
I am trying to use this code to close a form on a specific answer of a message box. I keep receiving an error saying that neither Yes
nor No
belong to DialogResult::
. I basically copied this code straight from the MS site, so i have no idea what's wrong. Help?
private: System::Void Form1_FormClosing(System::Object^ sender, System::Windows::Forms::FormClosingEventArgs^ e) {
if(!watchdog->Checked)
{
if((MessageBox::Show("CAN Watchdog is currently OFF. If you exit with these settings, the SENSOWheel will still be engaged. To prevent this, please enable CAN Watchdog before closing. Would you still like to quit?", "Watchdog Warning", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == DialogResult::No))
{
return;
}
else
{
close_Click(this, e);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
DialogResult
枚举与Form
的DialogResult
属性之间存在命名冲突。您想要前者,编译器假设您指的是后者。解决歧义的一种方法是完全限定对枚举的引用:
我在此找到了第二种方法 线程;将
using namespace System...
语句移出namespace
块,然后通过全局命名空间引用枚举。There is a naming clash between the
DialogResult
enumeration, and theDialogResult
property ofForm
. You want the former, the compiler assumes you are referring to the latter.One way to resolve the ambiguity is to fully-qualify your reference to the enum:
I found a second method in this thread; move the
using namespace System...
statements out of thenamespace
block, then refer to the enum via the global namespace.这是工作解决方案,其中有一些额外的代码,以便您可以看到整个图片。在此示例中,有一些正在运行的
BackgroundWorker
在应用程序关闭之前必须停止。Here is working solution which has some extra code so you can see the whole picture. In this example there is some working
BackgroundWorker
that must be stopped before app is gonna be closed.