How to get the background colour of the active (map) view

2648
3
02-01-2012 01:08 AM
Highlighted
New Contributor III
VB.NET & ArcMAP

Probably a rather simple question, but how do you get the background colour of the active view (in map view not layout). I.e. access the "date frame properties", "frame", "background colour". Am exporting the active view from arcmap into a png, but need to know the background colour to state what colour is transparent in the png. For the life of me i cannot work it out.

Any help is much appreciated

Thank You

Alex
Reply
0 Kudos
3 Replies
Highlighted
MVP Honored Contributor
From the help: IPage is the primary interface on the Page object. Use this interface to access  all the properties of an ArcMap page, including the border, background,  background color, orientation, and size.
Reply
0 Kudos
Highlighted
Regular Contributor III
Here's a VBA script that will set the background color to red.  You can modify it as needed.

Sub SetBackgroundColor()
    Dim mxDoc As IMxDocument
    Set mxDoc = ThisDocument
    Dim map As IMap
    Set map = mxDoc.FocusMap
    Dim layout As IPageLayout
    Set layout = mxDoc.PageLayout
    Dim gc As IGraphicsContainer
    Set gc = layout
    gc.Reset
   
    Dim element As IElement
    Set element = gc.Next
    Do While Not element Is Nothing
        If TypeOf element Is IMapFrame Then
            Dim mapFrame As IMapFrame
            Set mapFrame = element
            If mapFrame.map Is map Then
                Dim background As IBackground
                Set background = mapFrame.background
                Dim symbolBackground As ISymbolBackground
                Set symbolBackground = background
                Dim fillSymbol As IFillSymbol
                Set fillSymbol = symbolBackground.fillSymbol
                Dim color As IRgbColor
                Set color = New RgbColor
                color.Red = 255
                color.Green = 0
                color.Blue = 0
                fillSymbol.color = color
                symbolBackground.fillSymbol = fillSymbol
                mapFrame.background = background
                mxDoc.UpdateContents
                mxDoc.ActiveView.Refresh
            End If
        End If
       
        Set element = gc.Next
    Loop
End Sub
Reply
0 Kudos
Highlighted
New Contributor III
Fantastic, thank you
Reply
0 Kudos