Creating and Using an Event Handler

If you're familiar with Windows C development, you will understand the idea of handling messages as they arrive by the action of the WndProc switch statement. If you have been working with MFC, you will know that messages are routed through the message map of your application. Under .NET the message routing system is provided by delegates. Your application will define event handlers that are called through a delegate whenever a message arrives. Button clicks for example, can be handled by using a generic EventHandler delegate. Other types of events, such as mouse events or timer events, are serviced through specific handlers that have their own delegate signatures.

Adding a button to the Windows Forms application ...

Get C# and the .NET Framework: The C++ Perspective now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.