EditorEventsDialog.cs
// Copyright 2010 ESRI // // All rights reserved under the copyright laws of the United States // and applicable international laws, treaties, and conventions. // // You may freely redistribute and use this sample code, with or // without modification, provided you include the original copyright // notice and use restrictions. // // See the use restrictions. // using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.SystemUI; using ESRI.ArcGIS.Framework; using ESRI.ArcGIS.ADF; namespace Events { /// <summary> /// Designer class of the dockable window add-in. It contains user interfaces that /// make up the dockable window. /// </summary> public partial class EditorEventsDialog : UserControl { internal TabPage m_selectTab; internal TabPage m_listenTab; internal TabControl m_TabControl; internal static EditorEventsDialog e_dockWinForm; EventListener eventListener; private ESRI.ArcGIS.Editor.IEditor m_editor; public EditorEventsDialog(object hook) { InitializeComponent(); this.Hook = hook; e_dockWinForm = this; //get a reference to the editor UID uid = new UIDClass(); uid.Value = "esriEditor.Editor"; m_editor = ArcMap.Application.FindExtensionByCLSID(uid) as ESRI.ArcGIS.Editor.IEditor; m_TabControl = e_dockWinForm.tabControl1; System.Collections.IEnumerator e = m_TabControl.TabPages.GetEnumerator(); e.MoveNext(); m_listenTab = e.Current as TabPage; e.MoveNext(); m_selectTab = e.Current as TabPage; CheckedListBox editEventList = m_selectTab.GetNextControl(m_selectTab, true) as CheckedListBox; editEventList.ItemCheck += new ItemCheckEventHandler(editEventList_ItemCheck); ListBox listEvent = m_listenTab.GetNextControl(m_listenTab, true) as ListBox; listEvent.MouseDown += new MouseEventHandler(listEvent_MouseDown); eventListener = new EventListener(m_editor); eventListener.Changed += new ChangedEventHandler(eventListener_Changed); //populate the editor events editEventList.Items.AddRange(Enum.GetNames(typeof(EventListener.EditorEvent))); } /// <summary> /// Host object of the dockable window /// </summary> private object Hook { get; set; } /// <summary> /// Implementation class of the dockable window add-in. It is responsible for /// creating and disposing the user interface class of the dockable window. /// </summary> public class AddinImpl : ESRI.ArcGIS.Desktop.AddIns.DockableWindow { private EditorEventsDialog m_windowUI; public AddinImpl() { } protected override IntPtr OnCreateChild() { m_windowUI = new EditorEventsDialog(this.Hook); return m_windowUI.Handle; } protected override void Dispose(bool disposing) { if (m_windowUI != null) m_windowUI.Dispose(disposing); base.Dispose(disposing); } } void listEvent_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { this.lstEditorEvents.Items.Clear(); this.lstEditorEvents.Refresh(); } } void eventListener_Changed(object sender, EditorEventArgs e) { ((ListBox)m_listenTab.GetNextControl(m_listenTab, true)).Items.Add(e.eventType.ToString()); } void editEventList_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e) { // start or stop listening for event based on checked state eventListener.ListenToEvents((Events.EventListener.EditorEvent)e.Index, e.NewValue == CheckState.Checked); } } }