Time for action - creating the menu bar

  1. Double-click on the MapEditor.cs file in Solution Explorer to open the MapEditor form in the design window.
  2. Click on the empty MenuStrip you previously added to the form, and add menu entries for the following items:
    • &File
      • &Load Map
      • &Save Map
      • (A single dash, creating a separator line)
      • E&xit
    • &Tools
      • &Clear Map
    • &Layer
      • &Background
      • &Interactive
      • &Foreground
    Time for action - creating the menu bar
  3. Double-click on the Exit item under the File menu to have C# automatically generate an event handler for the Exit menu item.
  4. Enter the following code into the exitToolStripMenuItem_Click() event handler:
    game.Exit();
    Application.Exit();
    

What just happened?

We now have a standard Windows menu attached to our form with a few entries for our level editor. In order to add code to menu items other than the Exit command, we need to make modifications to our Game1 class, so we will come back to them after we have laid out all of the items on our display.

Tip

What are all those ampersands?

In step two above, each of the menu item entries contains an ampersand (&) character, usually as the first character in the entry. When the MenuStrip control sees these characters, instead of displaying them in the menu, it causes the next character in the name to be underlined and treated as a shortcut key. By labelling the File menu as&File, the item will be displayed as File, and pressing Alt + F will open the File menu. Items within the File menu can then be accessed by pressing their own shortcut keys (L for Load, S for Save, and so on).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.103.8