You are here: > ESRI Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - ArcObjects General forum

Catching the event generated by the Pan Too...   Ryan T Dec 15, 2004
Re: Catching the event generated by the Pan...   Michael Knight Dec 20, 2004
Re: Catching the event generated by the Pan...   Steve Clark Feb 15, 2007
Re: Catching the event generated by the Pan...   Jithendra Grandhi Jul 08, 2008
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Catching the event generated by the Pan Tool 
Author Ryan T 
Date Dec 15, 2004 
Message I'm having difficulty catching the event generated by the Pan tool. After reading through the posts on this forum, it was recommended that I listen in on ITransformEvents; however, this still does not seem to pickup on the event. Here is how I am currently implementing it (all I want it to do is popup a messagebox when the map is panned). Am I missing something here?:
 
 
private ESRI.ArcGIS.Display.ITransformEvents_VisibleBoundsUpdatedEventHandler visBoundsUpdatedE; 

visBoundsUpdatedE = new ESRI.ArcGIS.Display.ITransformEvents_VisibleBoundsUpdatedEventHandler(OnVisibleBoundsUpdated);
((ITransformEvents_Event)mapDocument.ActiveView.ScreenDisplay.DisplayTransformation).VisibleBoundsUpdated += visBoundsUpdatedE;

private void OnVisibleBoundsUpdated(IDisplayTransformation sender, bool theSizeChanged)
{
  MessageBox.Show("Visible Bounds Updated");
}
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Catching the event generated by the Pan Tool 
Author Michael Knight 
Date Dec 20, 2004 
Message I think it would be far easier to implement your own pan tool, like this one:

http://arcobjectsonline.esri.com/default.asp?URL=/ArcObjectsOnline/Samples/ArcMap/TrackPan.htm

There are also some .NET samples as well. Search for PanTool. 
  Michael Knight
GIS Solutions Architect
Contract Land Staff, LLC
Stafford, Texas

http://www.contractlandstaff.com

 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Catching the event generated by the Pan Tool 
Author Steve Clark 
Date Feb 15, 2007 
Message I don't think the response answered the question because it becomes irrelevant to what tool you could use instead but more of how and where events can be fired.

Here's what I just did in wanting to capture one bit of information whenever the user pans in a Map Frame:

In my BaseCommand class, I added the event handler declaration:

private ESRI.ArcGIS.Display.ITransformEvents_VisibleBoundsUpdatedEventHandler delVisibleBoundsUpdated;

In the same class, I added what the event does when it is called (as an example):

private void OnVisibleBoundsChanged(ESRI.ArcGIS.Display.IDisplayTransformation sender, bool theSizeChanged)
{
MessageBox.Show(sender.VisibleBounds.XMin.ToString() +
sender.VisibleBounds.YMin.ToString() +
sender.VisibleBounds.XMax.ToString() +
sender.VisibleBounds.YMax.ToString());
}

Now to wire the event to the MxDoc, I could have added it to the OnCreate function but I wanted to fire the event only when the public function is called. In other words, the event will fire only when the user users my command. I wired the event delegate like this:

delVisibleBoundsUpdated = new ESRI.ArcGIS.Display.ITransformEvents_VisibleBoundsUpdatedEventHandler(OnVisibleBoundsChanged);
((ESRI.ArcGIS.Display.ITransformEvents_Event)pMxDoc.ActivatedView.ScreenDisplay.DisplayTransformation).VisibleBoundsUpdated += delVisibleBoundsUpdated;

And in the same public method, I link the delegate to the active MxDoc:

OnVisibleBoundsChanged(pMxDoc.ActivatedView.ScreenDisplay.DisplayTransformation, true);

There are probably better places to put these or to trap so it is only called when I wanted it to, so I guess I will still be playing around with this.


 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Catching the event generated by the Pan Tool 
Author Jithendra Grandhi 
Date Jul 08, 2008 
Message Hi Ryan,
I'm also trying to implement the same, try to implement it as an IExtension instaed of going for ICommand.Here is the code for you :-)

 
 
public class EventListenerExt : IExtension
    {
        private IMxDocument _pMxDocument;
        private IDocument _pDocument;
   
        #region IExtension Members
        public string Name
        {
            get
            {
                return "events";
            }
        }

        public void Shutdown()
        {
            
        }

        public void Startup(ref object initializationData)
        {
            IApplication pApplication = initializationData as IApplication;

            try
            {
                _pDocument = pApplication.Document;
                SetUpDocEvents();
              
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
                    }
        #endregion

        void SetUpDocEvents()
        {
            try
            {
                ((IDocumentEvents_Event)_pDocument).NewDocument += new IDocumentEvents_NewDocumentEventHandler(EventListenerExt_NewDocument);
                ((IDocumentEvents_Event)_pDocument).OpenDocument += new IDocumentEvents_OpenDocumentEventHandler(EventListenerExt_OpenDocument);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
      }

        void EventListenerExt_OpenDocument()
        {
            try
            {
                _pMxDocument = _pDocument as IMxDocument;
                
               
                ((ITransformEvents_Event)_pMxDocument.ActiveView.ScreenDisplay.DisplayTransformation).VisibleBoundsUpdated += new ITransformEvents_VisibleBoundsUpdatedEventHandler(EventListenerExt_VisibleBoundsUpdated);
              
            }
            catch (Exception ex)
            {
               MessageBox.Show(ex.Message + ex.StackTrace);
            }
        }

       
       
        void EventListenerExt_NewDocument()
        {

        }

        void EventListenerExt_VisibleBoundsUpdated(IDisplayTransformation sender, bool sizeChanged)
        {
            IEnvelope pEnvelope;
            try
            {
                MessageBox.Show("entered into visiblebounds updated");
                pEnvelope = _pMxDocument.ActiveView.Extent.Envelope;
               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
            
        }