Building a Managed .NET Framework Application (7)
In order for your form to respond to user events, you’ll need to capture the button click events. Events that were previously handled with the MFC message map are handled quite differently in the .NET Framework. Events are handled by delegates within your class. A delegate is quite similar to a C/C++ function pointer. You assign delegates to handle object events with the following statement:
m_pbtnMessage->add_Click(
new System::EventHandler( this, &CHelloNETForm::OnMessageClick ) );
Every time the Message button is clicked, the CHelloNETForm::OnMessageClick() method is called. In your project, you will add two event handlers to the two buttons.
Event handlers must have a specific set of parameters, much in the same way they did for MFC message map handlers. For most events, pointers to a generic Object and an EventArgs object are passed as parameters. The generic Object pointer is a pointer to the object that caused the event, whereas the EventArgs object contains information specific to the event. Following the instructions given earlier, add two member functions. The first function is named OnMessageClick, and the second function is named OnDoneClick. Both functions have a void return type, protected access level, and two parameters: Object* source and EventArgs* e. Listing 3.3 shows the final version of the HelloNETForm.h file.
Taken From: SAMS-Tech Yourself MS Visual C++.NET in 24 Hours
Leave a Reply