Time for action – handling the FormClosed event

  1. Open the MapEditor form in Design mode.
  2. Select the form as the current object by clicking on the form's title bar in the Design window.
  3. Switch to Event editing mode in the Properties window by clicking on the lightning-bolt button.
  4. Scroll down to the FormClosed event and double-click in the empty box to the right of the event name to create the MapEditor_FormClosed() event handler.
  5. Update the event handler to read:
    private void MapEditor_FormClosed(
        object sender, 
        FormClosedEventArgs e)
    {
        game.Exit();
        Application.Exit();
    }

What just happened?

When the form closes, we need to shut down both the XNA game and the overall application, otherwise the system will not release the resources, and the program will ...

Get XNA 4.0 Game Development by Example Beginner's Guide 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.