views:

42

answers:

1

I copy

if ((MessageBox::Show(
     "Are you sure that you would like to close the form?", 
     "Form Closing", MessageBoxButtons::YesNo, 
     MessageBoxIcon::Question) == DialogResult::No))
  {
     // cancel the closure of the form.
     Application::Exit();
  }

From msdn. Where I compiling this i have

1>------ Build started: Project: test2, Configuration: Debug Win32 ------ 1> test2.cpp 1>c:\users\kredkołamacz\documents\visual studio 2010\projects\test2\test2\Form1.h(103): error C2039: 'No' : is not a member of 'System::Windows::Forms::Form::DialogResult' 1> c:\users\kredkołamacz\documents\visual studio 2010\projects\test2\test2\Form1.h(16) : see declaration of 'System::Windows::Forms::Form::DialogResult' 1>c:\users\kredkołamacz\documents\visual studio 2010\projects\test2\test2\Form1.h(103): error C2065: 'No' : undeclared identifier ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

What's wrong? How fix this problem?

+1  A: 

I’m stumped but the MSDN article for DialogResult mentions in the C++ example that the type name should be prefixed with :: to make it non-nested. Maybe try this:

if (MessageBox::Show(
     "Are you sure that you would like to close the form?", 
     "Form Closing", MessageBoxButtons::YesNo, 
     MessageBoxIcon::Question) == ::DialogResult::No)

(I also removed the redundant parentheses …)

If it doesn’t help, try specifying the full namespace, i.e. ::System::Windows::Forms::DialogResult::No to see if that at least works.

Konrad Rudolph
Work with ::System::Windows::Forms::DialogResult::No. Thanks. (I can't accept this answer now)
asd