Search code examples
.netnamespacesc++-climessagebox

Why does DialogResult::Yes require a ::?


Why does this work:

using namespace System;
using namespace System::Windows::Forms;
...
if( MessageBox::Show("Really do it?", "Are you sure?", System::Windows::Forms::MessageBoxButtons::YesNo) == System::Windows::Forms::DialogResult::Yes )
{
    Console::WriteLine("Do it!");
}

..when this fails:

using namespace System;
using namespace System::Windows::Forms;
...
if( MessageBox::Show("Really do it?", "Are you sure?", System::Windows::Forms::MessageBoxButtons::YesNo) == DialogResult::Yes )
{
    Console::WriteLine("Do it!");
}

...with the following error:

error C2039: 'Yes' : is not a member of 'System::Windows::Forms::Form::DialogResult'

I'm assuming Visual Studio is picking up DialogResult but I can't see where it's finding it?


Solution

  • System::Windows::Forms::Form has a property also called DialogResult (being of type System::Windows::Forms::DialogResult), hence the error.

    http://msdn.microsoft.com/library/system.windows.forms.form.dialogresult.aspx

    http://msdn.microsoft.com/library/system.windows.forms.dialogresult.aspx