This document is archived and information here might be outdated.  Recommended version.


Get ActiveView from ArcMap Snippet (ArcObjects .NET 10.6 SDK)
ArcObjects Library Reference

Get ActiveView from ArcMap Snippet

Get ActiveView from ArcMap.

[C#]
///<summary>Get ActiveView from ArcMap</summary>
///  
///<param name="application">An IApplication interface that is the ArcMap application.</param>
///   
///<returns>An IActiveView interface.</returns>
///   
///<remarks></remarks>
public ESRI.ArcGIS.Carto.IActiveView GetActiveViewFromArcMap(ESRI.ArcGIS.Framework.IApplication application)
{
  if (application == null)
  {
    return null;
  }
  ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument=application.Document as ESRI.ArcGIS.ArcMapUI.IMxDocument; // Dynamic Cast
  ESRI.ArcGIS.Carto.IActiveView activeView=mxDocument.ActiveView;

  return activeView;
}
[Visual Basic .NET]
'''<summary>Get ActiveView from ArcMap</summary>
'''  
'''<param name="application">An IApplication interface that is the ArcMap application.</param>
'''   
'''<returns>An IActiveView interface.</returns>
'''   
'''<remarks></remarks>
Public Function GetActiveViewFromArcMap(ByVal application As ESRI.ArcGIS.Framework.IApplication) As ESRI.ArcGIS.Carto.IActiveView

  If application Is Nothing Then
    Return Nothing
  End If

  Dim mxDocument As ESRI.ArcGIS.ArcMapUI.IMxDocument=TryCast(application.Document, ESRI.ArcGIS.ArcMapUI.IMxDocument) ' Dynamic Cast
  Dim activeView As ESRI.ArcGIS.Carto.IActiveView=mxDocument.ActiveView

  Return activeView

End Function

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.ArcMapUI
  • ESRI.ArcGIS.Carto
  • ESRI.ArcGIS.Framework
  • ESRI.ArcGIS.System