Handling Events from Menus

There are several events that you can handle from a MenuItem. The most important is the one that you defined the item for in the first place. Remember from our button click example earlier that the events are hooked to the Click event source by a delegate defined by the system. In Listing 3.1.7, a handler that pops up a message box is defined and added to the methods of the SizeApp class.

Listing 3.1.7. A Simple Event Handler
public class SizeApp : System.WinForms.Form
{

    public void OnFileOpen(Object sender, EventArgs e)
    {
        MessageBox.Show("You selected File-Open!");
    }

The event handler has the standard method signature for events void function(Object, EventArgs) and can be added to the File, Open MenuItem's Click ...

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.