Visual studio 2010 关闭messagebox上的表单回答问题
我试图使用此代码关闭消息框特定答案上的表单。我一直收到一个错误,说明Visual studio 2010 关闭messagebox上的表单回答问题,visual-studio-2010,visual-c++,messagebox,formclosing,dialogresult,Visual Studio 2010,Visual C++,Messagebox,Formclosing,Dialogresult,我试图使用此代码关闭消息框特定答案上的表单。我一直收到一个错误,说明Yes和No都不属于DialogResult::。我基本上是直接从微软网站上复制了这段代码,所以我不知道出了什么问题。帮忙 private: System::Void Form1_FormClosing(System::Object^ sender, System::Windows::Forms::FormClosingEventArgs^ e) { if(!watchdog->Checked
Yes
和No
都不属于DialogResult::
。我基本上是直接从微软网站上复制了这段代码,所以我不知道出了什么问题。帮忙
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);
}
}
}
如果((MessageBox::Show(“…”,“Watchdog Warning”,MessageBoxButtons::YesNo,MessageBoxIcon::Question)=
系统::Windows::窗体::对话框结果::否)
{
e->Cancel=true;//不关闭
}
如果((MessageBox::Show(“…”,“Watchdog Warning”,MessageBoxButtons::YesNo,MessageBoxIcon::Question)=
系统::Windows::窗体::对话框结果::否)
{
e->Cancel=true;//不关闭
}
DialogResult
枚举与Form
的DialogResult
属性之间存在命名冲突。如果您想要前者,编译器假定您引用的是后者
解决歧义的一种方法是完全限定对枚举的引用:
if((MessageBox::Show("CAN Watchdog ... Would you still like to quit?", "Watchdog Warning", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == System::Windows::Forms::DialogResult::No))
我在这方面找到了第二种方法;将using namespace System…
语句移出namespace
块,然后通过全局命名空间引用枚举
if((MessageBox::Show("CAN Watchdog ... Would you still like to quit?", "Watchdog Warning", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == ::DialogResult::No))
DialogResult
枚举与Form
的DialogResult
属性之间存在命名冲突。如果您想要前者,编译器假定您引用的是后者
解决歧义的一种方法是完全限定对枚举的引用:
if((MessageBox::Show("CAN Watchdog ... Would you still like to quit?", "Watchdog Warning", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == System::Windows::Forms::DialogResult::No))
我在这方面找到了第二种方法;将using namespace System…
语句移出namespace
块,然后通过全局命名空间引用枚举
if((MessageBox::Show("CAN Watchdog ... Would you still like to quit?", "Watchdog Warning", MessageBoxButtons::YesNo, MessageBoxIcon::Question) == ::DialogResult::No))
这是一个工作解决方案,它有一些额外的代码,所以你可以看到整个画面。在本例中,在关闭应用程序之前,必须停止一些正在工作的
BackgroundWorker
#pragma region Start/Stop/Exit
private: System::Void backgroundWorker1_RunWorkerCompleted(System::Object^ sender, System::ComponentModel::RunWorkerCompletedEventArgs^ e) {
if(e->Cancelled)
{
rtbLog->Text = rtbLog->Text + ">>> Application stopped \n";
}
else
{
rtbLog->Text = rtbLog->Text + ">>> Application completed \n";
}
}
private: System::Void startToolStripMenuItemStart_Click(System::Object^ sender, System::EventArgs^ e)
{
if (backgroundWorker1->IsBusy == false)
{
backgroundWorker1->RunWorkerAsync(1); //starting background worker
}
}
private: System::Void stopToolStripMenuItemStop_Click(System::Object^ sender, System::EventArgs^ e)
{
if (backgroundWorker1->IsBusy == true && backgroundWorker1->WorkerSupportsCancellation == true)
{
backgroundWorker1->CancelAsync();
}
}
private: System::Void Form1_FormClosing(System::Object^ sender, System::Windows::Forms::FormClosingEventArgs^ e) {
if((MessageBox::Show("Would you still like to quit?", "Warning", MessageBoxButtons::YesNo, MessageBoxIcon::Question) ==
System::Windows::Forms::DialogResult::No))
{
e->Cancel = true; // Don't close and BackgroundWoker is executing.
}
else
{
if (backgroundWorker1->IsBusy == true && backgroundWorker1->WorkerSupportsCancellation == true)
{
backgroundWorker1->CancelAsync();
}
}
}
private: System::Void exitToolStripMenuItemExit_Click(System::Object^ sender, System::EventArgs^ e) {
Application::Exit(); // The user wants to exit the application. Close everything down.
}
#pragma endregion
这是一个工作解决方案,它有一些额外的代码,所以你可以看到整个画面。在本例中,在关闭应用程序之前,必须停止一些正在工作的
BackgroundWorker
#pragma region Start/Stop/Exit
private: System::Void backgroundWorker1_RunWorkerCompleted(System::Object^ sender, System::ComponentModel::RunWorkerCompletedEventArgs^ e) {
if(e->Cancelled)
{
rtbLog->Text = rtbLog->Text + ">>> Application stopped \n";
}
else
{
rtbLog->Text = rtbLog->Text + ">>> Application completed \n";
}
}
private: System::Void startToolStripMenuItemStart_Click(System::Object^ sender, System::EventArgs^ e)
{
if (backgroundWorker1->IsBusy == false)
{
backgroundWorker1->RunWorkerAsync(1); //starting background worker
}
}
private: System::Void stopToolStripMenuItemStop_Click(System::Object^ sender, System::EventArgs^ e)
{
if (backgroundWorker1->IsBusy == true && backgroundWorker1->WorkerSupportsCancellation == true)
{
backgroundWorker1->CancelAsync();
}
}
private: System::Void Form1_FormClosing(System::Object^ sender, System::Windows::Forms::FormClosingEventArgs^ e) {
if((MessageBox::Show("Would you still like to quit?", "Warning", MessageBoxButtons::YesNo, MessageBoxIcon::Question) ==
System::Windows::Forms::DialogResult::No))
{
e->Cancel = true; // Don't close and BackgroundWoker is executing.
}
else
{
if (backgroundWorker1->IsBusy == true && backgroundWorker1->WorkerSupportsCancellation == true)
{
backgroundWorker1->CancelAsync();
}
}
}
private: System::Void exitToolStripMenuItemExit_Click(System::Object^ sender, System::EventArgs^ e) {
Application::Exit(); // The user wants to exit the application. Close everything down.
}
#pragma endregion
这是一个C++问题,它不为类型标识符保留单独的符号表。您必须完全键入名称以避免表单::DeaultRESULTS的歧义。它是C++问题,它不为类型标识符保留单独的符号表。您必须完整地键入名称,以避免与Form::DialogResult之间的歧义。