How to display the map extent in GxView as an envelope


This command takes the current displayed data layer and draws the data extent in a thick red line in the preview.
The code samples in this section show the fundamentals of programming with ArcObjects. A careful reading of them gives you all the important concepts you need for developing with ArcObjects, as well as an introduction to the most important ArcObjects components.
The code can be typed or copied into the VBA environment in ArcMap or ArcCatalog, after which you can follow through with the VBA debugger.

How to use

  1. Add the code to the Click event of a UIButtonControl in ArcCatalog.
[VBA]
Dim pGxApp As IGxApplication
Set pGxApp = Application

Dim pGxView As IGxView
Set pGxView = pGxApp.View
If (TypeOf pGxView Is IGxPreview) Then
    Dim pGxPreview As IGxPreview
    Set pGxPreview = pGxView
    
    If (TypeOf pGxPreview.View Is IGxGeographicView) Then
        Dim pGxGeoView As IGxGeographicView
        Set pGxGeoView = pGxPreview.View
        
        Dim pEnv As IEnvelope
        Set pEnv = pGxGeoView.DisplayedLayer.AreaOfInterest
        
        Dim pLineSymbol As ISimpleLineSymbol
        Set pLineSymbol = New SimpleLineSymbol
        
        Dim pColor As IColor
        Set pColor = New RgbColor
        
        pColor.RGB = vbRed
        With pLineSymbol
            .Color = pColor
            .Width = 2
        End With
        
        Dim pFillSymbol As ISimpleFillSymbol
        Set pFillSymbol = New SimpleFillSymbol
        
        With pFillSymbol
            .Style = esriSFSHollow
            .Outline = pLineSymbol
        End With
        
        With pGxGeoView.MapDisplay
            .StartDrawing 0, esriNoScreenCache
            .SetSymbol pFillSymbol
            .DrawRectangle pEnv
            .FinishDrawing
        End With
    End If
End If