How do I add an event handler tied to a Form's Closed event?

  • Thread starter Thread starter hernan.silberman
  • Start date Start date
H

hernan.silberman

Hi folks,

I'm new to Windows programming and am diving into managed Visual C++.
I'm trying to tie an event handler to the closing of a Form and I need
help understanding what I'm doing wrong. This is from TestApp.cpp:


__delegate void CloseHandler(String*);

void TestApp::handleFormClose(String *aMsg)
{
Console::WriteLine("form closed!");
}

void TestApp::doInitUi()
{
myMainForm = new MainForm(); // System::Windows::Forms:Form data
member

// Add a listener to our form so we know when it's closed.
myMainForm->OnClosed +=
new CloseHandler( this, &TestApp::handleFormClose ); // error
is here
}

Here's the error I'm getting:
....\TestApp.cpp(55): error C2475:
'System::Windows::Forms::Form::OnClosed' :
forming a pointer-to-member requires explicit use of the
address-of operator ('&') and a qualified name

I don't see what I'm doing incorrectly, but I'm new to this. I
appreciate any help seeing my error.

thanks much,
Hernan
 
Got it working with this code, please let me know if this isn't a good
way to do this:

void TestApp::handleFormClose(Object* aSrc, EventArgs* anArgs)
{
Console::WriteLine("form closed!");
}

void TestApp::doInitUi()
{
myMainForm = new MainForm();

EventHandler* theH =
new EventHandler( this, &TestApp::handleFormClose );
myMainForm->add_Closed( theH );
}

works great.
thanks, sorry for the extra group traffic.
hernan
 
Back
Top