Programming Menus

As I've said before, every menu item is a unique object—that's why you were able to change the name for each item you created. Although individual menu items aren't controls as such, adding code behind them is very similar to adding code behind a control. You're now going to add code to the Quit and Ask Before Closing menu items.

Follow these steps to create the exit code:

Click the File menu now to open it.
Double-click the Quit menu item. Just as when you double-click a control, Visual C# .NET displays the code editor with the default event for the menu item you've clicked. For menu items, this is the Click event.
Enter the following code:
As you know by now, this code closes the current form. This ...

Get Sams Teach Yourself Microsoft® Visual C#™ .NET in 24 Hours now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.