IActiveView Events

632
2
03-16-2011 09:38 AM
GregRieck
Occasional Contributor III
Hello,

Does anyone have any C# sample code for setting up the IActiveViewEvents Interface that they would be willing to share?

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/IActiveViewEvents_Interf...

G
0 Kudos
2 Replies
BradChappell
New Contributor
First create the delegates (class level):

private IActiveViewEvents_ItemAddedEventHandler m_ActiveViewEventsItemAdded;
private IActiveViewEvents_ItemDeletedEventHandler m_ActiveViewEventsItemDeleted;
private IActiveViewEvents_AfterItemDrawEventHandler m_ActiveViewEventsAfterItemDraw;

Wire the events inside class constructor:

//Create an instance of the delegate, add it to ItemAdded event
m_ActiveViewEventsItemAdded = new IActiveViewEvents_ItemAddedEventHandler(OnActiveViewEventsItemAdded);
            ((IActiveViewEvents_Event)(m_TheDoc.FocusMap)).ItemAdded += m_ActiveViewEventsItemAdded;

//Create an instance of the delegate, add it to ItemDeleted event
m_ActiveViewEventsItemDeleted = new IActiveViewEvents_ItemDeletedEventHandler(OnActiveViewEventsItemDeleted);
            ((IActiveViewEvents_Event)(m_TheDoc.FocusMap)).ItemDeleted += m_ActiveViewEventsItemDeleted;

//Create an instance of the delegate, add it to ItemDeleted event
m_ActiveViewEventsAfterItemDraw = new IActiveViewEvents_AfterItemDrawEventHandler(OnActiveViewEventsAfterItemDraw);
            ((IActiveViewEvents_Event)(m_TheDoc.FocusMap)).AfterItemDraw += m_ActiveViewEventsAfterItemDraw;


Create the Event handlers:

//Event handler
        private void OnActiveViewEventsItemAdded(object Item)
        {
                 //Code to execute
        }

        //Event handler
        private void OnActiveViewEventsItemDeleted(object Item)
        {
                 //Code to execute
        }

        //Event handler
        private void OnActiveViewEventsAfterItemDraw(short index, IDisplay display, esriDrawPhase phase)
        {
            if (phase == esriDrawPhase.esriDPGeography)
            {
                //Code to execute
            }
        }
0 Kudos
GregRieck
Occasional Contributor III
Brad,

Thank you for your response. I wasn't sure what the event parameters were and I couldn't find anything in the help doc's. I was specifically looking to trap for the AfterDraw event. Now today I've found the complete interface exposed through an ArcGIS snippet. I always forget to check those. Thanks again for your help.

Greg
0 Kudos