O'Reilly logo

Applied Microsoft® .NET Framework Programming by Jeffrey Richter

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Designing a Type That Listens for an Event

The hard work is definitely behind you at this point. In this section, I’ll show you how to define a type that uses an event provided by another type. Let’s start off by examining the code for the Fax type:

class Fax { // Pass the MailManager object to the constructor. public Fax(MailManager mm) { // Construct an instance of the MailMsgEventHandler // delegate that refers to the FaxMsg callback method. // Register the callback with MailManager's MailMsg event. mm.MailMsg += new MailManager.MailMsgEventHandler(FaxMsg); } // This is the method that MailManager will call to // notify the Fax object that a new e-mail message has arrived. private void FaxMsg( Object sender, MailManager.MailMsgEventArgs e) { ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required