public void ZoomToLayerInTOC(ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument) { if (mxDocument == null) { return; } ESRI.ArcGIS.Carto.IActiveView activeView = mxDocument.ActiveView; // Get the TOC ESRI.ArcGIS.ArcMapUI.IContentsView IContentsView = mxDocument.CurrentContentsView; ESRI.ArcGIS.Geometry.IEnvelope envelope = activeView.Extent; // ESRI.ArcGIS.Geometry.IEnvelope envelope = activeView.Extent; envelope.Expand(0.75, 0.75, true); activeView.Extent = envelope; activeView.Refresh(); System.Threading.Thread.Sleep(3000); envelope.Expand(0.75, 0.75, true); activeView.Extent = envelope; activeView.Refresh(); System.Threading.Thread.Sleep(3000); // Get the selected layer System.Object selectedItem = IContentsView.SelectedItem; if (!(selectedItem is ESRI.ArcGIS.Carto.ILayer)) { return; } ESRI.ArcGIS.Carto.ILayer layer = selectedItem as ESRI.ArcGIS.Carto.ILayer; // Zoom to the extent of the layer and refresh the map activeView.Extent = layer.AreaOfInterest; activeView.Refresh(); }
Solved! Go to Solution.
Thanks for replying. Well im not really sure what am I supposed to do. I mean I don't know how. By Separate thread you mean create a function? 😞
I think you might only be able to do this with a timer (which runs on a seperate thread, so beware of threading.) I tried it and looks like the view waits for the processing (sleep) to be finished on the main thread before it redraws.
Thanks for replying. Well im not really sure what am I supposed to do. I mean I don't know how. By Separate thread you mean create a function? 😞
Have you tried making a call to Application.DoEvents* in between the first Refresh and the Sleep?
*warning - many people have strong feelings about using DoEvents
Dim App As New Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase App.DoEvents()
Have you tried making a call to Application.DoEvents* in between the first Refresh and the Sleep?
*warning - many people have strong feelings about using DoEvents
Have you tried making a call to Application.DoEvents* in between the first Refresh and the Sleep?
*warning - many people have strong feelings about using DoEvents
Well i tried and to my surprise ... it worked! 🙂 Thank you very much!