转自原文 IEngineEditor与IWorkspaceEdit,以及相关的事件监听

IEngineEditor适用于直接在图层上的编辑,例如使用“要素编辑”工具菜单上的“开始编辑”等工具进行编辑,相应的事件使用IWorkspaceEdit监听,例如以下的代码:

private IEngineEditor m_EngineEditor = new EngineEditorClass();
private IEngineEditEvents_Event m_EngineEditEvents ;
private void MainForm_Load(object sender,EventArgs e)
{
//get the MapControl
m_mapControl = (IMapControl3)axMapControl1.Object;
//disable the Save menu (since there is no document yet)
menuSaveDoc.Enabled = false;
m_EngineEditEvents = (IEngineEditEvents_Event)m_EngineEditor;
m_EngineEditEvents.OnStartEditing += new IEngineEditEvents_OnStartEditingEventHandler(m_EngineEditEvents_OnStartEditing);
}
void m_EngineEditEvents_OnStartEditing()
{
MessageBox.Show("Start Editing");
}

IWorkspaceEdit适用于直接对workspace进行的编辑,相应的事件使用IWorkspaceEditEvents_Event监听,例如以下的代码:

private IWorkspaceEdit wsEdit;
private IWorkspaceEditEvents_Event wsEditEvents;
private void MainForm_Load(object sender,EventArgs e)
{
//get the MapControl
m_mapControl = (IMapControl3)axMapControl1.Object;
//disable the Save menu (since there is no document yet)
menuSaveDoc.Enabled = false;
wsEdit = MyTool.GetWorkspaceEdit(map1.Map);
wsEditEvents = (IWorkspaceEditEvents_Event)wsEdit;
wsEditEvents.OnStopEditing += new IWorkspaceEditEvents_OnStopEditingEventHandler(wsEditEvents_OnStopEditing);
}
void wsEditEvents_OnStopEditing(bool saveEdits)
{
MessageBox.Show("StopEditing");
}
04-24 19:44