In this topic
About listening to IEngineEditEvents
The IEngineEditEvents interface is an outbound interface on the EngineEditor singleton object that notifies listeners of editing actions. Events can be fired in response to end user interaction or program logic. For example, the IEngineEditEvents.OnStartEditing event is raised by using the out-of-the-box ControlsEditingStartCommand or when IEngineEditor.StartEditing is called.
To listen for specific IEngineEditEvents, create an event handler that is linked with the event using a delegate. The delegate holds a reference to a method that executes if the event is fired. The event handler method must have the same signature as the delegate. This process is known as wiring. For more information, see How to wire ArcObjects .NET events.
Listening to IEngineEditEvents
To listen to IEngineEditEvents, perform the following steps. In the following code example, a listener is created to determine when an editing session has started.
- At the class level, declare the following two variables:
- Variable to the EngineEditor singleton object
- Variable to the IEngineEditEvents interface
In .NET, event interfaces are automatically suffixed with _Event by the type library importer.
private EngineEditor m_EngineEditor=new EngineEditorClass();
private IEngineEditEvents_Event m_EngineEditEvents;
[VB.NET] Private m_EngineEditor As EngineEditor=New ESRI.ArcGIS.Controls.EngineEditorClass()
Private m_EngineEditEvents As IEngineEditEvents_Event
- In the Form_Load, cast the IEngineEditEvents interface to the EngineEditor singleton object. See the following code example:
m_EngineEditEvents=(IEngineEditEvents_Event)m_EngineEditor;
[VB.NET] m_EngineEditEvents=CType(m_EngineEditor, IEngineEditEvents_Event)
- In the Form_Load, register the event handler method that will be called when the event is fired. Use the AddHandler statement (VB .NET) or the += statement (C#) to register the event handler method. See the following code example:
m_EngineEditEvents.OnStartEditing += new
IEngineEditEvents_OnStartEditingEventHandler(OnStartEditingMethod);
[VB.NET] AddHandler m_EngineEditEvents.OnStartEditing, AddressOf OnStartEditingMethod
- At the class level, define the method that is performed when the IEngineEditEvents.OnStartEditing event is fired. See the following code example:
private void OnStartEditingMethod()
{
System.Windows.Forms.MessageBox.Show("Editing Started");
}
[VB.NET] Private Sub OnStartEditingMethod()
System.Windows.Forms.MessageBox.Show("Editing Started")
End Sub
Event order
One editing command or method may fire a number of specific IEngineEditEvents. See the following:
- OnStartEditing, OnSelectionChanged, and OnSketchModified events are fired when the IEngineEditor.StartEditing method is called or when a user executes the ControlsEditingStartCommand.
- OnSketchModified, OnAfterDrawSketch, and OnCurrentTaskChanged events are fired when the IEngineEditor.CurrentTask property is called or when a user selects a new edit task from the ControlsEditingTaskToolControl.
- OnTargetLayerChanged and OnStopEditing events are fired when the IEngineEditor.StopEditing method is called or when a user uses the ControlsEditingStopCommand.
It is important to understand the order in which events are fired so that customized code associated with the events executes in the correct order.
See Also:
How to wire ArcObjects .NET eventsHow to create an edit session
How to create a sketch operation
How to work with the operation stack
To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
- ESRI.ArcGIS.Controls
- ESRI.ArcGIS.Geodatabase
- ESRI.ArcGIS.System (ESRI.ArcGIS.esriSystem)
Development licensing | Deployment licensing |
---|---|
Engine Developer Kit | Engine |
ArcGIS for Desktop Basic | |
ArcGIS for Desktop Standard | |
ArcGIS for Desktop Advanced |