Occurs when a map document is closed, for example when a new map is opened.

Namespace:  ESRI.ArcGISExplorer.Application

Assembly:  ESRI.ArcGISExplorer.Application (in ESRI.ArcGISExplorer.Application.dll) Version: 2.0.0.1500 (2.0.0.1500)

Syntax

C#
public static event EventHandler DocumentClosed
Visual Basic (Declaration)
Public Shared Event DocumentClosed As EventHandler

Remarks

This event occurs when a map document is closed in the application; the event is triggered when before the existing document is closed and therefore the MapDisplay and Map of the existing document are still available in the event handler.

This event is an ideal place to release any variables that point to any of the objects existing in a Map, as after this event is complete, the MapDisplay, Map, and all its child items will become invalid when the map document is closed disposed.

It is a common practice to sink both the DocumentOpened and DocumentClosed events in order to set and release variables correctly.

Examples

The code below shows how you can add event handlers for the DocumentOpened and DocumentClosed event from within an Extension class. The Extension uses the DocumentOpened event to store a variable pointing to the current Map, and the DocumentClosed event to relinquish this variable. It uses the static ActiveMapDisplay member of the Application class. This code assumes you may have a using/imports statement for the System.Windows.Forms namespace, and therefore the Application class is fully qualified in order to avoid conflicts.
CopyC#
using System;
using System.Text;

// Import some typical namespaces.
using System.Windows.Forms;
using System.Drawing;

// Additional ArcGIS Explorer namespaces.
using ESRI.ArcGISExplorer.Application;
using ESRI.ArcGISExplorer.Mapping;

namespace EventExtension
{
  class DocumentEventsExtension : ESRI.ArcGISExplorer.Application.Extension
  {
    private string appCap = null;
    private Map currentMap = null;

    public override void OnStartup()
    {
      // Add event handlers for the DocumentOpened and DocumentClosed events.
      ESRI.ArcGISExplorer.Application.Application.DocumentOpened += new EventHandler(Application_DocumentOpened);
      ESRI.ArcGISExplorer.Application.Application.DocumentClosed += new EventHandler(Application_DocumentClosed);

      // A Document is already open at this point, so run the event handler once now to initialize.
      Application_DocumentOpened(null, null);
    }

    public override void OnShutdown()
    {
      // Remove the handlers for the events.
      ESRI.ArcGISExplorer.Application.Application.DocumentOpened -= new EventHandler(Application_DocumentOpened);
      ESRI.ArcGISExplorer.Application.Application.DocumentClosed -= new EventHandler(Application_DocumentClosed);

      // DocumentClosed will not be triggered on exit, so run the event handler once now to tidy up.
      Application_DocumentClosed(null, null);
   }

    void Application_DocumentOpened(object sender, EventArgs e)
    {
      // Perform some initialization of your extension based on the document which is open.
      // For example, store a reference to the MapDisplay or Map.
      appCap = ESRI.ArcGISExplorer.Application.Application.Caption;
      currentMap = ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay.Map;
    }

    void Application_DocumentClosed(object sender, EventArgs e)
    {
      // Relinquish any variables pointing to the document.
      currentMap = null;

      // If called from OnShutdown, the Application and MapDisplay are still valid at this point.
    }
  }
}
CopyVB.NET
Imports System
Imports System.Text

' Import some typical namespaces.
Imports System.Windows.Forms
Imports System.Drawing

' Additional ArcGIS Explorer namespaces.
Imports ESRI.ArcGISExplorer.Application
Imports ESRI.ArcGISExplorer.Mapping


Namespace EventExtension

  Public Class DocumentEventsExtension
    Inherits ESRI.ArcGISExplorer.Application.Extension

    Private appCap As String = Nothing
    Private currentMap As Map = Nothing


    Public Overrides Sub OnStartup()
      ' Add event handlers for the DocumentOpened and DocumentClosed events.
      AddHandler ESRI.ArcGISExplorer.Application.Application.DocumentOpened, AddressOf Application_DocumentOpened
      AddHandler ESRI.ArcGISExplorer.Application.Application.DocumentClosed, AddressOf Application_DocumentClosed

      ' A Document is already open at this point, so run the event handler once now to initialize.
      Application_DocumentOpened(Nothing, Nothing)
    End Sub


    Public Overrides Sub OnShutdown()
      ' Remove the handlers for the events.
      RemoveHandler ESRI.ArcGISExplorer.Application.Application.DocumentOpened, AddressOf Application_DocumentOpened
      RemoveHandler ESRI.ArcGISExplorer.Application.Application.DocumentClosed, AddressOf Application_DocumentClosed

      ' DocumentClosed will not be triggered on exit, so run the event handler once now to tidy up.
      Application_DocumentClosed(Nothing, Nothing)
    End Sub


    Sub Application_DocumentOpened(ByVal sender As Object, ByVal e As EventArgs)
      ' Perform some initialization of your extension based on the document which is open.
      ' For example, store a reference to the MapDisplay or Map.
      appCap = ESRI.ArcGISExplorer.Application.Application.Caption
      currentMap = ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay.Map
    End Sub

    Sub Application_DocumentClosed(ByVal sender As Object, ByVal e As EventArgs)
      ' Relinquish any variables pointing to the document.
      currentMap = Nothing
      ' If called from OnShutdown, the Application and MapDisplay are still valid at this point.
    End Sub
  End Class
End Namespace

See Also