This documentation is archived and is not being maintained.

How to: Sink Windows Forms Events from Native C++ Classes 

You can enable native C++ classes to receive callbacks from managed events raised from Windows Forms controls or other forms with the MFC macro map format. Sinking events in views and dialogs is similar to doing the same task for controls.

To do this, you need to:


This sample continues the work you did in How to: Do DDX/DDV Data Binding with Windows Forms.

Now, you will associate your MFC control (m_MyControl) with a managed event handler delegate called OnClick for the managed Click event.

Add the first line of code to implementation of BOOL CMFC01Dlg::OnInitDialog.

Add the delegate map and OnClick definition to the public section in the declaration of class CMFC01Dlg : public CDialog.

m_MyControl.GetControl()->button1->Click += MAKE_DELEGATE( System::EventHandler, OnClick );

// delegate map
EVENT_DELEGATE_ENTRY( OnClick, System::Object^, System::EventArgs^ )

   void OnClick( System::Object^ sender, System::EventArgs^ e ) {}

See Also