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:

1.
Click the File menu now to open it.
2.
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.
3.
Enter the following code:
this.Close();
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 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.