Getting element Width and Height values in [Properties -> Size and Position] dialog?

11-06-2011 10:40 PM
New Contributor
In ArcMap UI, when element selection tool is selected, right-clicking the graphic element shows popup menu, if we click "Properties" item the Properties dialog is shown. How could I programmatically get the same values as being shown in "Width" and "Height" fields at the "Size and Position" tab of the dialog? Assumed I have a particular IElement in the code, for which I have to find these values, and I need the solution to work with IMapSurroundFrame-based elements also. The screenshot is attached, sorry for non-English localization of the software, I hope it's clear enough what is needed.
0 Kudos
1 Reply
MVP Frequent Contributor

This code gets to the width and height of a graphic:

Public Sub test()
    ' Get the map and the graphics container for it
    Dim pMap As IMap
    Dim pMXDocument As IMxDocument
    Set pMXDocument = ThisDocument
    Set pMap = pMXDocument.FocusMap
    Dim pGraphicsContainer As IGraphicsContainer
    Set pGraphicsContainer = pMap
    ' Get the first element
    Dim pElement As IElement
    Set pElement = pGraphicsContainer.Next
    ' Get the name property and display
    Dim pElementProperties As IElementProperties
    Set pElementProperties = pElement
    MsgBox pElementProperties.Name
    ' Get the width and height and display
    Dim pEnvelope As IEnvelope
    Set pEnvelope = New Envelope
    Dim pDisplay As IDisplay
    Set pDisplay = pMXDocument.ActiveView.ScreenDisplay
    pElement.QueryBounds pDisplay, pEnvelope
    MsgBox CStr(pEnvelope.Width), vbInformation, "width"
    MsgBox CStr(pEnvelope.Height), vbInformation, "height"
End Sub

Another Interface is IBoundsProperties. This code worked well for a circle but I noticed that when I drew a polyline graphic it's width was different to what the dialog was reporting, not sure why.

0 Kudos