This document is archived and information here might be outdated. Recommended version. |
ArcObjects Help for .NET developers > ESRI.ArcGIS.Snippets > Snippets > Add Event Wiring for New and Open Documents Snippet (ArcObjects .NET 10.4 SDK) |
Wire event when a document is created or opened in ArcGIS desktop applications.
/// <summary> /// Event member variable /// </summary> /// <remarks></remarks> private ESRI.ArcGIS.ArcMapUI.IDocumentEvents_Event m_docEvents=null; /// <summary> /// Set up the wiring of the events. /// </summary> /// <param name="myDocument"></param> /// <remarks></remarks> private void SetUpDocumentEvent(ESRI.ArcGIS.Framework.IDocument myDocument) { m_docEvents=myDocument as ESRI.ArcGIS.ArcMapUI.IDocumentEvents_Event; m_docEvents.NewDocument += new ESRI.ArcGIS.ArcMapUI.IDocumentEvents_NewDocumentEventHandler(OnNewDocument); m_docEvents.OpenDocument += new ESRI.ArcGIS.ArcMapUI.IDocumentEvents_OpenDocumentEventHandler(OnOpenDocument); } /// <summary> /// The NewDocument event handler. /// </summary> /// <remarks></remarks> void OnNewDocument() { ESRI.ArcGIS.Framework.IDocument theDocument=m_docEvents as ESRI.ArcGIS.Framework.IDocument; //TODO: Add your document handler event code } /// <summary> /// The OpenDocument event handler. /// </summary> /// <remarks></remarks> void OnOpenDocument() { ESRI.ArcGIS.Framework.IDocument theDocument=m_docEvents as ESRI.ArcGIS.Framework.IDocument; //TODO: Add your document handler event code }
''' <summary> ''' Event member variable ''' </summary> ''' <remarks></remarks> Private m_docEvents As ESRI.ArcGIS.ArcMapUI.IDocumentEvents_Event ''' <summary> ''' Set up the wiring of the events. ''' </summary> ''' <param name="myDocument"></param> ''' <remarks></remarks> Private Sub SetUpDocumentEvent(myDocument As ESRI.ArcGIS.Framework.IDocument) m_docEvents=CType(myDocument, ESRI.ArcGIS.ArcMapUI.IDocumentEvents_Event) AddHandler m_docEvents.NewDocument, AddressOf OnNewDocument AddHandler m_docEvents.OpenDocument, AddressOf OnOpenDocument End Sub ''' <summary> ''' The NewDocument event handler. ''' </summary> ''' <remarks></remarks> Private Sub OnNewDocument() Dim theDocument As ESRI.ArcGIS.Framework.IDocument=CType(m_docEvents, ESRI.ArcGIS.Framework.IDocument) 'TODO: Add your document handler event code End Sub ''' <summary> ''' The OpenDocument event handler. ''' </summary> ''' <remarks></remarks> Private Sub OnOpenDocument() Dim theDocument As ESRI.ArcGIS.Framework.IDocument=CType(m_docEvents, ESRI.ArcGIS.Framework.IDocument) 'TODO: Add your document handler event code End Sub