views:

314

answers:

1

When I write the following:

private: System::Void queue_FormClosing(
    System::Object^ sender, 
    System::Windows::Forms::FormClosingEventArgs^ e) {
    if(e->CloseReason!=CloseReason::FormOwnerClosing) e->Cancel=true;
}

I get this error:

###\queue.h(153) : error C2039: 'FormOwnerClosing' : is not a member of 'System::Windows::Forms::Form::CloseReason' 1>###\queue.h(24) : see declaration of 'System::Windows::Forms::Form::CloseReason' 1>###\queue.h(153) : error C2065: 'FormOwnerClosing' : undeclared identifier

I don't understand why this is. Can anybody help?

+2  A: 

For some reason you need to fully qualify the enum as System::Windows::Forms::CloseReason::FormOwnerClosing.

Doesn't compile:

private: System::Void Form1_FormClosing(System::Object^  sender,
                 System::Windows::Forms::FormClosingEventArgs^  e) {
  if (e->CloseReason == CloseReason::FormOwnerClosing) {
    e->Cancel = true;
  }
}

Does compile:

private: System::Void Form1_FormClosing(System::Object^  sender,
                 System::Windows::Forms::FormClosingEventArgs^  e) {
  if (e->CloseReason == System::Windows::Forms::CloseReason::FormOwnerClosing) {
    e->Cancel = true;
  }
}

No idea why you need to fully qualify it, but it allows it to compile.

Joshua
thx :) thats why i hate ms ;D
n00b32
@n00b32 - You hate Microsoft because you don't have sufficient skills to use their products? Very odd...
Greg Beech
@greg its not about skill :) its about the wierd illogical rules that run their products
n00b32
or you could just use a "using namespace" directive
ferrari fan
I suppose you could add a `using System::Windows::Forms::CloseReason;` to get it to work, but the `using namespace System::Windows::Forms;` is already at the top of the file.
Joshua