ArcObjects Library Reference  

EventListener

About the Edit event listener Sample

[C#]

EventListener.cs

using System;
using System.Collections.Generic;
using System.Text;
using ESRI.ArcGIS.Editor;

namespace Events
{
  public class EventListener
  {
    #region Enums
    //contains all edit events listed on IEditEvents through IEditEvents4
    public enum EditorEvent
    {
      AfterDrawSketch,
      OnChangeFeature,
      OnConflictsDetected,
      OnCreateFeature, 
      OnCurrentLayerChanged,
      OnCurrentTaskChanged,
      OnDeleteFeature,
      OnRedo,
      OnSelectionChanged,
      OnSketchFinished,
      OnSketchModified,
      OnStartEditing,
      OnStopEditing,
      OnUndo,
      BeforeStopEditing,
      BeforeStopOperation,
      OnVertexAdded,
      OnVertexMoved,
      OnVertexDeleted,
      BeforeDrawSketch,
      OnAngularCorrectionOffsetChanged,
      OnDistanceCorrectionFactorChanged,
      OnUseGroundToGridChanged,
    };
    #endregion

    #region Constructors
    public EventListener(IEditor editor)
    {
      if (editor == null)
      {
        throw new ArgumentNullException();
      }

      m_editor = editor;

    }
    public EventListener(IEditor editor, EditorEvent editEvent)
    {
      if (editor == null)
      {
        throw new ArgumentNullException();
      }

      m_editor = editor;

    }
    EventListener(IEditor editor, bool bListenAll)
    {
      if (editor == null)
      {
        throw new ArgumentNullException();
      }

      m_editor = editor;
    }
    #endregion

    public void ListenToEvents(EditorEvent editEvent, bool start)
    {
      switch (editEvent)
      {
        case EditorEvent.AfterDrawSketch:
          if (start)
            ((IEditEvents_Event)m_editor).AfterDrawSketch += new 
              IEditEvents_AfterDrawSketchEventHandler(EventListener_AfterDrawSketch);
          else
            ((IEditEvents_Event)m_editor).AfterDrawSketch -= new
              IEditEvents_AfterDrawSketchEventHandler(EventListener_AfterDrawSketch);
          break;
        case EditorEvent.OnChangeFeature:
          if (start)
            ((IEditEvents_Event)m_editor).OnChangeFeature += new 
              IEditEvents_OnChangeFeatureEventHandler(EventListener_OnChangeFeature); 
          else
            ((IEditEvents_Event)m_editor).OnChangeFeature -= new
              IEditEvents_OnChangeFeatureEventHandler(EventListener_OnChangeFeature);
          break;
        case EditorEvent.OnConflictsDetected:
          if (start)
            ((IEditEvents_Event)m_editor).OnConflictsDetected += new 
              IEditEvents_OnConflictsDetectedEventHandler(EventListener_OnConflictsDetected);
          else
            ((IEditEvents_Event)m_editor).OnConflictsDetected -= new
              IEditEvents_OnConflictsDetectedEventHandler(EventListener_OnConflictsDetected);
          break;
        case EditorEvent.OnCreateFeature:
          if (start)
            ((IEditEvents_Event)m_editor).OnCreateFeature += new 
              IEditEvents_OnCreateFeatureEventHandler(EventListener_OnCreateFeature);
          else
            ((IEditEvents_Event)m_editor).OnCreateFeature -= new
              IEditEvents_OnCreateFeatureEventHandler(EventListener_OnCreateFeature);
          break;

        case EditorEvent.OnCurrentLayerChanged:
          if (start)
            ((IEditEvents_Event)m_editor).OnCurrentLayerChanged += new 
              IEditEvents_OnCurrentLayerChangedEventHandler(EventListener_OnCurrentLayerChanged); 
          else
            ((IEditEvents_Event)m_editor).OnCurrentLayerChanged -= new
              IEditEvents_OnCurrentLayerChangedEventHandler(EventListener_OnCurrentLayerChanged);
          break;
        case EditorEvent.OnCurrentTaskChanged:
          if (start)
          ((IEditEvents_Event)m_editor).OnCurrentTaskChanged += new 
            IEditEvents_OnCurrentTaskChangedEventHandler(OnCurrentTaskChanged);
          else
          ((IEditEvents_Event)m_editor).OnCurrentTaskChanged -= new
            IEditEvents_OnCurrentTaskChangedEventHandler(OnCurrentTaskChanged);
          break;
        case EditorEvent.OnDeleteFeature:
          if (start)
            ((IEditEvents_Event)m_editor).OnDeleteFeature += new 
              IEditEvents_OnDeleteFeatureEventHandler(EventListener_OnDeleteFeature);
          else
            ((IEditEvents_Event)m_editor).OnDeleteFeature -= new
              IEditEvents_OnDeleteFeatureEventHandler(EventListener_OnDeleteFeature);
          break;
        case EditorEvent.OnRedo:
          if (start)
            ((IEditEvents_Event)m_editor).OnRedo += new 
              IEditEvents_OnRedoEventHandler(EventListener_OnRedo); 
          else
            ((IEditEvents_Event)m_editor).OnRedo -= new
              IEditEvents_OnRedoEventHandler(EventListener_OnRedo);
          break;
        case EditorEvent.OnSelectionChanged:
          if (start)
            ((IEditEvents_Event)m_editor).OnSelectionChanged +=new 
              IEditEvents_OnSelectionChangedEventHandler(EventListener_OnSelectionChanged); 
          else
            ((IEditEvents_Event)m_editor).OnSelectionChanged -= new
              IEditEvents_OnSelectionChangedEventHandler(EventListener_OnSelectionChanged);
          break;
        case EditorEvent.OnSketchFinished:
          if (start)
            ((IEditEvents_Event)m_editor).OnSketchFinished += new 
              IEditEvents_OnSketchFinishedEventHandler(EventListener_OnSketchFinished);
          else
            ((IEditEvents_Event)m_editor).OnSketchFinished -= new
              IEditEvents_OnSketchFinishedEventHandler(EventListener_OnSketchFinished); 
          break;
        case EditorEvent.OnSketchModified:
          if (start)
            ((IEditEvents_Event)m_editor).OnSketchModified += new 
              IEditEvents_OnSketchModifiedEventHandler(EventListener_OnSketchModified);
          else
            ((IEditEvents_Event)m_editor).OnSketchModified -= new
              IEditEvents_OnSketchModifiedEventHandler(EventListener_OnSketchModified);
          break;
        case EditorEvent.OnStartEditing:
          if (start)
            ((IEditEvents_Event)m_editor).OnStartEditing += new
              IEditEvents_OnStartEditingEventHandler(OnStartEditing);
          else
            ((IEditEvents_Event)m_editor).OnStartEditing -= new
              IEditEvents_OnStartEditingEventHandler(OnStartEditing); 
          break;          
        case EditorEvent.OnStopEditing:
          if (start)
            ((IEditEvents_Event)m_editor).OnStopEditing += new 
              IEditEvents_OnStopEditingEventHandler(OnStopEditing);
          else
            ((IEditEvents_Event)m_editor).OnStopEditing -= new
              IEditEvents_OnStopEditingEventHandler(OnStopEditing); 
          break;
        case EditorEvent.OnUndo:
          if (start)
            ((IEditEvents_Event)m_editor).OnUndo += new 
              IEditEvents_OnUndoEventHandler(EventListener_OnUndo); 
          else
            ((IEditEvents_Event)m_editor).OnUndo -= new
              IEditEvents_OnUndoEventHandler(EventListener_OnUndo);
          break;
        case EditorEvent.BeforeStopEditing:
          if (start)
            ((IEditEvents2_Event)m_editor).BeforeStopEditing += new 
              IEditEvents2_BeforeStopEditingEventHandler(EventListener_BeforeStopEditing); 
          else
            ((IEditEvents2_Event)m_editor).BeforeStopEditing -= new
              IEditEvents2_BeforeStopEditingEventHandler(EventListener_BeforeStopEditing);
          break;
        case EditorEvent.BeforeStopOperation:
          if (start)
            ((IEditEvents2_Event)m_editor).BeforeStopOperation += new 
              IEditEvents2_BeforeStopOperationEventHandler(EventListener_BeforeStopOperation);
          else
            ((IEditEvents2_Event)m_editor).BeforeStopOperation -= new
              IEditEvents2_BeforeStopOperationEventHandler(EventListener_BeforeStopOperation);
          break;
        case EditorEvent.OnVertexAdded:
          if (start)
            ((IEditEvents2_Event)m_editor).OnVertexAdded +=new 
              IEditEvents2_OnVertexAddedEventHandler(EventListener_OnVertexAdded); 
          else
            ((IEditEvents2_Event)m_editor).OnVertexAdded -= new
              IEditEvents2_OnVertexAddedEventHandler(EventListener_OnVertexAdded);
          break;
        case EditorEvent.OnVertexMoved:
          if (start)
            ((IEditEvents2_Event)m_editor).OnVertexMoved += new 
              IEditEvents2_OnVertexMovedEventHandler(EventListener_OnVertexMoved); 
          else
            ((IEditEvents2_Event)m_editor).OnVertexMoved -= new
              IEditEvents2_OnVertexMovedEventHandler(EventListener_OnVertexMoved);
          break;
        case EditorEvent.OnVertexDeleted:
          if (start)
            ((IEditEvents2_Event)m_editor).OnVertexDeleted += new 
              IEditEvents2_OnVertexDeletedEventHandler(EventListener_OnVertexDeleted);              
          else
            ((IEditEvents2_Event)m_editor).OnVertexDeleted -= new
              IEditEvents2_OnVertexDeletedEventHandler(EventListener_OnVertexDeleted);
          break;
        case EditorEvent.BeforeDrawSketch:
          if (start)
            ((IEditEvents3_Event)m_editor).BeforeDrawSketch += new 
              IEditEvents3_BeforeDrawSketchEventHandler(EventListener_BeforeDrawSketch);              
          else
            ((IEditEvents3_Event)m_editor).BeforeDrawSketch -= new 
              IEditEvents3_BeforeDrawSketchEventHandler(EventListener_BeforeDrawSketch);              
          break;
        case EditorEvent.OnAngularCorrectionOffsetChanged:
          if (start)
            ((IEditEvents4_Event)m_editor).OnAngularCorrectionOffsetChanged += new 
              IEditEvents4_OnAngularCorrectionOffsetChangedEventHandler(EventListener_OnAngularCorrectionOffsetChanged);              
          else
            ((IEditEvents4_Event)m_editor).OnAngularCorrectionOffsetChanged -= new 
              IEditEvents4_OnAngularCorrectionOffsetChangedEventHandler(EventListener_OnAngularCorrectionOffsetChanged);              
          break;
        case EditorEvent.OnDistanceCorrectionFactorChanged:
          if (start)
            ((IEditEvents4_Event)m_editor).OnDistanceCorrectionFactorChanged += new 
              IEditEvents4_OnDistanceCorrectionFactorChangedEventHandler(EventListener_OnDistanceCorrectionFactorChanged); 
          else
            ((IEditEvents4_Event)m_editor).OnDistanceCorrectionFactorChanged -= new 
              IEditEvents4_OnDistanceCorrectionFactorChangedEventHandler(EventListener_OnDistanceCorrectionFactorChanged); 
          break;
        case EditorEvent.OnUseGroundToGridChanged:
          if (start)
            ((IEditEvents4_Event)m_editor).OnUseGroundToGridChanged += new 
              IEditEvents4_OnUseGroundToGridChangedEventHandler(EventListener_OnUseGroundToGridChanged);
        
          else
            ((IEditEvents4_Event)m_editor).OnUseGroundToGridChanged -= new 
              IEditEvents4_OnUseGroundToGridChangedEventHandler(EventListener_OnUseGroundToGridChanged);
          break;
        default:
          break;

      }

    }

    // Invoke the Changed event
    protected virtual void OnChanged(EditorEventArgs e)
    {
      if (Changed != null)
        Changed(this, e);
    }

    #region Event Handlers
    void EventListener_OnCreateFeature(ESRI.ArcGIS.Geodatabase.IObject obj)
    {
      EditorEventArgs e = new EditorEventArgs("OnCreateFeature");
      OnChanged(e); 
    }
    void EventListener_OnChangeFeature(ESRI.ArcGIS.Geodatabase.IObject obj)
    {
      EditorEventArgs e = new EditorEventArgs("OnChangeFeature");
      OnChanged(e); 
    }
    void EventListener_OnConflictsDetected()
    {
      EditorEventArgs e = new EditorEventArgs("OnConflictsDetected");
      OnChanged(e); 
    }
    void EventListener_OnCurrentLayerChanged()
    {
      EditorEventArgs e = new EditorEventArgs("OnCurrentLayerChanged");
      OnChanged(e); 
    }
    void EventListener_OnDeleteFeature(ESRI.ArcGIS.Geodatabase.IObject obj)
    {
      EditorEventArgs e = new EditorEventArgs("OnDeleteFeature");
      OnChanged(e); 
    }
    void EventListener_OnRedo()
    {
      EditorEventArgs e = new EditorEventArgs("OnRedo");
      OnChanged(e); 
    }
    void EventListener_OnSelectionChanged()
    {
      EditorEventArgs e = new EditorEventArgs("OnSelectionChanged");
      OnChanged(e); 
    }
    void EventListener_OnSketchFinished()
    {
      EditorEventArgs e = new EditorEventArgs("OnSketchFinished");
      OnChanged(e); 
    }
    void EventListener_OnSketchModified()
    {
      EditorEventArgs e = new EditorEventArgs("OnSketchModified");
      OnChanged(e); 
    }
    void EventListener_OnUndo()
    {
      EditorEventArgs e = new EditorEventArgs("OnUndo");
      OnChanged(e); 
    }
    void EventListener_BeforeStopEditing(bool save)
    {
      EditorEventArgs e = new EditorEventArgs("BeforeStopEditing");
      OnChanged(e); 
    }
    void EventListener_BeforeStopOperation()
    {
      EditorEventArgs e = new EditorEventArgs("BeforeStopOperation");
      OnChanged(e); 
    }
    void EventListener_OnVertexAdded(ESRI.ArcGIS.Geometry.IPoint point)
    {
      EditorEventArgs e = new EditorEventArgs("OnVertexAdded");
      OnChanged(e);     
    }
    void EventListener_OnVertexMoved(ESRI.ArcGIS.Geometry.IPoint point)
    {
      EditorEventArgs e = new EditorEventArgs("OnVertexMoved");
      OnChanged(e);    
    }
    void EventListener_OnVertexDeleted(ESRI.ArcGIS.Geometry.IPoint point)
    {
      EditorEventArgs e = new EditorEventArgs("OnVertexDeleted");
      OnChanged(e);    
    }
    void EventListener_OnAngularCorrectionOffsetChanged(double angOffset)
    {
      EditorEventArgs e = new EditorEventArgs("OnAngularCorrectionOffsetChanged");
      OnChanged(e);     
    }
    void EventListener_OnDistanceCorrectionFactorChanged(double distFactor)
    {
      EditorEventArgs e = new EditorEventArgs("OnDistanceCorrectionFactorChanged");
      OnChanged(e);    
    }
    void EventListener_OnUseGroundToGridChanged(bool g2g)
    {
      EditorEventArgs e = new EditorEventArgs("OnUseGroundToGridChanged");
      OnChanged(e); 
    }
    void EventListener_BeforeDrawSketch(ESRI.ArcGIS.Display.IDisplay pDpy)
    {
      EditorEventArgs e = new EditorEventArgs("BeforeDrawSketch");
      OnChanged(e); 
    }
    void EventListener_AfterDrawSketch(ESRI.ArcGIS.Display.IDisplay pDpy)
    {
      EditorEventArgs e = new EditorEventArgs("AfterDrawSketch");
      OnChanged(e); 
    }
    void OnCurrentTaskChanged()
    {
      EditorEventArgs e = new EditorEventArgs("OnCurrentTaskChanged");
      OnChanged(e);   
    }
    void OnStopEditing(bool SaveEdits)
    {
      EditorEventArgs e = new EditorEventArgs("OnStopEditing");
      OnChanged(e);    
    }
    void OnStartEditing()
    {
      EditorEventArgs e = new EditorEventArgs("OnStartEditing");
      OnChanged(e);
    }
    #endregion

    #region Members

    public event ChangedEventHandler Changed;
    
    IEditor m_editor;
    #endregion
  }

  public class EditorEventArgs : EventArgs
  {
    public EditorEventArgs(string eventType)
    {
      this.eventType = eventType;
    }
    public string eventType;
  }

  public delegate void ChangedEventHandler(object sender, EditorEventArgs e);
}

[Visual Basic .NET]

EventListener.vb

Imports System.Collections.Generic
Imports System.Text
Imports System.Runtime.InteropServices
Imports ESRI.ArcGIS.Editor

<ComClass(EventListener.ClassId, EventListener.InterfaceId, EventListener.EventsId), _
 ProgId("VBNet.EventListener")> _
Public Class EventListener

#Region "COM GUIDs"
    ' These  GUIDs provide the COM identity for this class 
    ' and its COM interfaces. If you change them, existing 
    ' clients will no longer be able to access the class.
    Public Const ClassId As String = "6c41019b-5be8-4c55-9fbe-ddf63fe0c67a"
    Public Const InterfaceId As String = "e661f2e8-c840-4d50-a93e-a88e2308c4c6"
    Public Const EventsId As String = "39bbcf43-ffce-4504-b9b6-8c35bb6d7eed"
#End Region

    ' A creatable COM class must have a Public Sub New() 
    ' with no parameters, otherwise, the class will not be 
    ' registered in the COM registry and cannot be created 
    ' via CreateObject.
    Public Sub New()
        MyBase.New()
    End Sub

#Region "Members"
    Public Event Changed As ChangedEventHandler
    Private m_editor As IEditor
#End Region

#Region "Enums"
    'contains all edit events listed on IEditEvents through IEditEvents4
    Public Enum EditorEvent
        AfterDrawSketch
        OnChangeFeature
        OnConflictsDetected
        OnCreateFeature
        OnCurrentLayerChanged
        OnCurrentTaskChanged
        OnDeleteFeature
        OnRedo
        OnSelectionChanged
        OnSketchFinished
        OnSketchModified
        OnStartEditing
        OnStopEditing
        OnUndo
        BeforeStopEditing
        BeforeStopOperation
        OnVertexAdded
        OnVertexMoved
        OnVertexDeleted
        BeforeDrawSketch
        OnAngularCorrectionOffsetChanged
        OnDistanceCorrectionFactorChanged
        OnUseGroundToGridChanged
    End Enum
#End Region

    ' Invoke the Changed event
    Protected Overridable Sub OnChanged(ByVal e As EditorEventArgs)
        If Not ChangedEvent Is Nothing Then
            RaiseEvent Changed(Me, e)
        End If
    End Sub

    ''' <summary>
    ''' Adds or removes the correct event handler based on the event and if it is checked.
    ''' </summary>
    ''' <param name="editEvent"></param>
    ''' <param name="start"></param>
    Public Sub ListenToEvents(ByVal editEvent As EditorEvent, ByVal start As Boolean)
        Select Case editEvent
            Case EditorEvent.AfterDrawSketch
                If start Then
                    AddHandler (CType(m_editor, IEditEvents_Event)).AfterDrawSketch, AddressOf EventListener_AfterDrawSketch
                Else
                    RemoveHandler (CType(m_editor, IEditEvents_Event)).AfterDrawSketch, AddressOf EventListener_AfterDrawSketch
                End If

            Case EditorEvent.OnChangeFeature
                If start Then
                    AddHandler (CType(m_editor, IEditEvents_Event)).OnChangeFeature, AddressOf EventListener_OnChangeFeature
                Else
                    RemoveHandler (CType(m_editor, IEditEvents_Event)).OnChangeFeature, AddressOf EventListener_OnChangeFeature
                End If

            Case EditorEvent.OnConflictsDetected
                If start Then
                    AddHandler (CType(m_editor, IEditEvents_Event)).OnConflictsDetected, AddressOf EventListener_OnConflictsDetected
                Else
                    RemoveHandler (CType(m_editor, IEditEvents_Event)).OnConflictsDetected, AddressOf EventListener_OnConflictsDetected
                End If

            Case EditorEvent.OnCreateFeature
                If start Then
                    AddHandler (CType(m_editor, IEditEvents_Event)).OnCreateFeature, AddressOf EventListener_OnCreateFeature
                Else
                    RemoveHandler (CType(m_editor, IEditEvents_Event)).OnCreateFeature, AddressOf EventListener_OnCreateFeature
                End If

            Case EditorEvent.OnCurrentLayerChanged
                If start Then
                    AddHandler (CType(m_editor, IEditEvents_Event)).OnCurrentLayerChanged, AddressOf EventListener_OnCurrentLayerChanged
                Else
                    RemoveHandler (CType(m_editor, IEditEvents_Event)).OnCurrentLayerChanged, AddressOf EventListener_OnCurrentLayerChanged
                End If

            Case EditorEvent.OnCurrentTaskChanged
                If start Then
                    AddHandler (CType(m_editor, IEditEvents_Event)).OnCurrentTaskChanged, AddressOf OnCurrentTaskChanged
                Else
                    RemoveHandler (CType(m_editor, IEditEvents_Event)).OnCurrentTaskChanged, AddressOf OnCurrentTaskChanged
                End If

            Case EditorEvent.OnDeleteFeature
                If start Then
                    AddHandler (CType(m_editor, IEditEvents_Event)).OnDeleteFeature, AddressOf EventListener_OnDeleteFeature
                Else
                    RemoveHandler (CType(m_editor, IEditEvents_Event)).OnDeleteFeature, AddressOf EventListener_OnDeleteFeature
                End If

            Case EditorEvent.OnRedo
                If start Then
                    AddHandler (CType(m_editor, IEditEvents_Event)).OnRedo, AddressOf EventListener_OnRedo
                Else
                    RemoveHandler (CType(m_editor, IEditEvents_Event)).OnRedo, AddressOf EventListener_OnRedo
                End If

            Case EditorEvent.OnSelectionChanged
                If start Then
                    AddHandler (CType(m_editor, IEditEvents_Event)).OnSelectionChanged, AddressOf EventListener_OnSelectionChanged
                Else
                    RemoveHandler (CType(m_editor, IEditEvents_Event)).OnSelectionChanged, AddressOf EventListener_OnSelectionChanged
                End If

            Case EditorEvent.OnSketchFinished
                If start Then
                    AddHandler (CType(m_editor, IEditEvents_Event)).OnSketchFinished, AddressOf EventListener_OnSketchFinished
                Else
                    RemoveHandler (CType(m_editor, IEditEvents_Event)).OnSketchFinished, AddressOf EventListener_OnSketchFinished
                End If

            Case EditorEvent.OnSketchModified
                If start Then
                    AddHandler (CType(m_editor, IEditEvents_Event)).OnSketchModified, AddressOf EventListener_OnSketchModified
                Else
                    RemoveHandler (CType(m_editor, IEditEvents_Event)).OnSketchModified, AddressOf EventListener_OnSketchModified
                End If

            Case EditorEvent.OnStartEditing
                If start Then
                    AddHandler (CType(m_editor, IEditEvents_Event)).OnStartEditing, AddressOf OnStartEditing
                Else
                    RemoveHandler (CType(m_editor, IEditEvents_Event)).OnStartEditing, AddressOf OnStartEditing
                End If

            Case EditorEvent.OnStopEditing
                If start Then
                    AddHandler (CType(m_editor, IEditEvents_Event)).OnStopEditing, AddressOf OnStopEditing
                Else
                    RemoveHandler (CType(m_editor, IEditEvents_Event)).OnStopEditing, AddressOf OnStopEditing
                End If

            Case EditorEvent.OnUndo
                If start Then
                    AddHandler (CType(m_editor, IEditEvents_Event)).OnUndo, AddressOf EventListener_OnUndo
                Else
                    RemoveHandler (CType(m_editor, IEditEvents_Event)).OnUndo, AddressOf EventListener_OnUndo
                End If

            Case EditorEvent.BeforeStopEditing
                If start Then
                    AddHandler (CType(m_editor, IEditEvents2_Event)).BeforeStopEditing, AddressOf EventListener_BeforeStopEditing
                Else
                    RemoveHandler (CType(m_editor, IEditEvents2_Event)).BeforeStopEditing, AddressOf EventListener_BeforeStopEditing
                End If

            Case EditorEvent.BeforeStopOperation
                If start Then
                    AddHandler (CType(m_editor, IEditEvents2_Event)).BeforeStopOperation, AddressOf EventListener_BeforeStopOperation
                Else
                    RemoveHandler (CType(m_editor, IEditEvents2_Event)).BeforeStopOperation, AddressOf EventListener_BeforeStopOperation
                End If

            Case EditorEvent.OnVertexAdded
                If start Then
                    AddHandler (CType(m_editor, IEditEvents2_Event)).OnVertexAdded, AddressOf EventListener_OnVertexAdded
                Else
                    RemoveHandler (CType(m_editor, IEditEvents2_Event)).OnVertexAdded, AddressOf EventListener_OnVertexAdded
                End If

            Case EditorEvent.OnVertexMoved
                If start Then
                    AddHandler (CType(m_editor, IEditEvents2_Event)).OnVertexMoved, AddressOf EventListener_OnVertexMoved
                Else
                    RemoveHandler (CType(m_editor, IEditEvents2_Event)).OnVertexMoved, AddressOf EventListener_OnVertexMoved
                End If

            Case EditorEvent.OnVertexDeleted
                If start Then
                    AddHandler (CType(m_editor, IEditEvents2_Event)).OnVertexDeleted, AddressOf EventListener_OnVertexDeleted
                Else
                    RemoveHandler (CType(m_editor, IEditEvents2_Event)).OnVertexDeleted, AddressOf EventListener_OnVertexDeleted
                End If

            Case EditorEvent.BeforeDrawSketch
                If start Then
                    AddHandler (CType(m_editor, IEditEvents3_Event)).BeforeDrawSketch, AddressOf EventListener_BeforeDrawSketch
                Else
                    RemoveHandler (CType(m_editor, IEditEvents3_Event)).BeforeDrawSketch, AddressOf EventListener_BeforeDrawSketch
                End If

            Case EditorEvent.OnAngularCorrectionOffsetChanged
                If start Then
                    AddHandler (CType(m_editor, IEditEvents4_Event)).OnAngularCorrectionOffsetChanged, AddressOf EventListener_OnAngularCorrectionOffsetChanged
                Else
                    RemoveHandler (CType(m_editor, IEditEvents4_Event)).OnAngularCorrectionOffsetChanged, AddressOf EventListener_OnAngularCorrectionOffsetChanged
                End If

            Case EditorEvent.OnDistanceCorrectionFactorChanged
                If start Then
                    AddHandler (CType(m_editor, IEditEvents4_Event)).OnDistanceCorrectionFactorChanged, AddressOf EventListener_OnDistanceCorrectionFactorChanged
                Else
                    RemoveHandler (CType(m_editor, IEditEvents4_Event)).OnDistanceCorrectionFactorChanged, AddressOf EventListener_OnDistanceCorrectionFactorChanged
                End If

            Case EditorEvent.OnUseGroundToGridChanged
                If start Then
                    AddHandler (CType(m_editor, IEditEvents4_Event)).OnUseGroundToGridChanged, AddressOf EventListener_OnUseGroundToGridChanged
                Else
                    RemoveHandler (CType(m_editor, IEditEvents4_Event)).OnUseGroundToGridChanged, AddressOf EventListener_OnUseGroundToGridChanged
                End If

            Case Else
        End Select
    End Sub

#Region "Constructors"
    Public Sub New(ByVal editor As IEditor)
        If editor Is Nothing Then
            Throw New ArgumentNullException()
        End If

        m_editor = editor
    End Sub

    Public Sub New(ByVal editor As IEditor, ByVal editEvent As EditorEvent)
        If editor Is Nothing Then
            Throw New ArgumentNullException()
        End If

        m_editor = editor
    End Sub

    Private Sub New(ByVal editor As IEditor, ByVal bListenAll As Boolean)
        If editor Is Nothing Then
            Throw New ArgumentNullException()
        End If

        m_editor = editor
    End Sub

#End Region

#Region "Event Handlers"
    Private Sub EventListener_OnCreateFeature(ByVal obj As ESRI.ArcGIS.Geodatabase.IObject)
        Dim e As EditorEventArgs = New EditorEventArgs("OnCreateFeature")
        OnChanged(e)
    End Sub

    Private Sub EventListener_OnChangeFeature(ByVal obj As ESRI.ArcGIS.Geodatabase.IObject)
        Dim e As EditorEventArgs = New EditorEventArgs("OnChangeFeature")
        OnChanged(e)
    End Sub

    Private Sub EventListener_OnConflictsDetected()
        Dim e As EditorEventArgs = New EditorEventArgs("OnConflictsDetected")
        OnChanged(e)
    End Sub

    Private Sub EventListener_OnCurrentLayerChanged()
        Dim e As EditorEventArgs = New EditorEventArgs("OnCurrentLayerChanged")
        OnChanged(e)
    End Sub

    Private Sub EventListener_OnDeleteFeature(ByVal obj As ESRI.ArcGIS.Geodatabase.IObject)
        Dim e As EditorEventArgs = New EditorEventArgs("OnDeleteFeature")
        OnChanged(e)
    End Sub

    Private Sub EventListener_OnRedo()
        Dim e As EditorEventArgs = New EditorEventArgs("OnRedo")
        OnChanged(e)
    End Sub

    Private Sub EventListener_OnSelectionChanged()
        Dim e As EditorEventArgs = New EditorEventArgs("OnSelectionChanged")
        OnChanged(e)
    End Sub

    Private Sub EventListener_OnSketchFinished()
        Dim e As EditorEventArgs = New EditorEventArgs("OnSketchFinished")
        OnChanged(e)
    End Sub

    Private Sub EventListener_OnSketchModified()
        Dim e As EditorEventArgs = New EditorEventArgs("OnSketchModified")
        OnChanged(e)
    End Sub

    Private Sub EventListener_OnUndo()
        Dim e As EditorEventArgs = New EditorEventArgs("OnUndo")
        OnChanged(e)
    End Sub

    Private Sub EventListener_BeforeStopEditing(ByVal save As Boolean)
        Dim e As EditorEventArgs = New EditorEventArgs("BeforeStopEditing")
        OnChanged(e)
    End Sub

    Private Sub EventListener_BeforeStopOperation()
        Dim e As EditorEventArgs = New EditorEventArgs("BeforeStopOperation")
        OnChanged(e)
    End Sub

    Private Sub EventListener_OnVertexAdded(ByVal point As ESRI.ArcGIS.Geometry.IPoint)
        Dim e As EditorEventArgs = New EditorEventArgs("OnVertexAdded")
        OnChanged(e)
    End Sub

    Private Sub EventListener_OnVertexMoved(ByVal point As ESRI.ArcGIS.Geometry.IPoint)
        Dim e As EditorEventArgs = New EditorEventArgs("OnVertexMoved")
        OnChanged(e)
    End Sub

    Private Sub EventListener_OnVertexDeleted(ByVal point As ESRI.ArcGIS.Geometry.IPoint)
        Dim e As EditorEventArgs = New EditorEventArgs("OnVertexDeleted")
        OnChanged(e)
    End Sub

    Private Sub EventListener_OnAngularCorrectionOffsetChanged(ByVal angOffset As Double)
        Dim e As EditorEventArgs = New EditorEventArgs("OnAngularCorrectionOffsetChanged")
        OnChanged(e)
    End Sub

    Private Sub EventListener_OnDistanceCorrectionFactorChanged(ByVal distFactor As Double)
        Dim e As EditorEventArgs = New EditorEventArgs("OnDistanceCorrectionFactorChanged")
        OnChanged(e)
    End Sub

    Private Sub EventListener_OnUseGroundToGridChanged(ByVal g2g As Boolean)
        Dim e As EditorEventArgs = New EditorEventArgs("OnUseGroundToGridChanged")
        OnChanged(e)
    End Sub

    Private Sub EventListener_BeforeDrawSketch(ByVal pDpy As ESRI.ArcGIS.Display.IDisplay)
        Dim e As EditorEventArgs = New EditorEventArgs("BeforeDrawSketch")
        OnChanged(e)
    End Sub

    Private Sub EventListener_AfterDrawSketch(ByVal pDpy As ESRI.ArcGIS.Display.IDisplay)
        Dim e As EditorEventArgs = New EditorEventArgs("AfterDrawSketch")
        OnChanged(e)
    End Sub

    Private Sub OnCurrentTaskChanged()
        Dim e As EditorEventArgs = New EditorEventArgs("OnCurrentTaskChanged")
        OnChanged(e)
    End Sub

    Private Sub OnStopEditing(ByVal SaveEdits As Boolean)
        Dim e As EditorEventArgs = New EditorEventArgs("OnStopEditing")
        OnChanged(e)
    End Sub

    Private Sub OnStartEditing()
        Dim e As EditorEventArgs = New EditorEventArgs("OnStartEditing")
        OnChanged(e)
    End Sub

#End Region

End Class

Public Class EditorEventArgs
    Inherits EventArgs

    Public Sub New(ByVal eventType As String)
        Me.eventType = eventType
    End Sub

    Public eventType As String
End Class

Public Delegate Sub ChangedEventHandler(ByVal sender As Object, ByVal e As EditorEventArgs)