Occurs when a map document is opened in the application.

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 DocumentOpened
Visual Basic (Declaration)
Public Shared Event DocumentOpened As EventHandler

Remarks

This event occurs when a map document is opened in the application; the event is triggered after a new document is opened, and therefore the MapDisplay and Map are available when this event occurs.

Note that if you wish to sink this event from an Extension, the OnStartup()()() method will be called after the first map has been opened; this is to ensure that the MapDisplay and Map are available in the OnStartup method.

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