How to set the map frame's background color


This sample changes the focus map's background color to a shade of blue. The image below shows two map frames: the one on the left has its IFrameElement::Background property set to Nothing while the one on the right is using a blue SymbolBackground object.

How to use

  1. Paste this macro into VBA.
  2. Modify the color as desired.
  3. Run the macro.
  4. Works in both layout view and data view.
[VBA]
Public Sub ChangeMapFrameBackground()
    Dim pActiveView As IActiveView
    Dim pFillSymbol As IFillSymbol
    Dim pLayoutGraphicsContainer As IGraphicsContainer
    Dim pMapFrame As IFrameElement
    Dim pMxDoc As IMxDocument
    Dim pRgbColor As IRgbColor
    Dim pSymbolBackground As ISymbolBackground
    
    'Get a reference to the layout's graphics container
    Set pMxDoc = Application.Document
    Set pLayoutGraphicsContainer = pMxDoc.PageLayout
    
    'Find the map frame associated with the focus map
    Set pMapFrame = pLayoutGraphicsContainer.FindFrame(pMxDoc.FocusMap)
    If pMapFrame Is Nothing Then Exit Sub
    
    'Associate a SymbolBackground with the frame
    Set pSymbolBackground = pMapFrame.Background
    If pSymbolBackground Is Nothing Then
        Set pSymbolBackground = New SymbolBackground
    End If
    Set pFillSymbol = New SimpleFillSymbol
    Set pRgbColor = New RgbColor
    pRgbColor.Blue = 200
    pRgbColor.Green = 130
    pFillSymbol.Color = pRgbColor
    pSymbolBackground.FillSymbol = pFillSymbol
    pMapFrame.Background = pSymbolBackground
    
    'Refresh the map frame
    Set pActiveView = pMxDoc.FocusMap
    pActiveView.PartialRefresh esriViewBackground, Nothing, Nothing
End Sub