How to add a text callout to the active view


This sample adds one of the more complicated types of graphic elements to a map or page layout, depending on the current view. The callout is added to the center of the view.
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 ArcMap, and execute the command when in Page View.
[VBA]
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument

Dim pTextElement As ITextElement
Set pTextElement = New TextElement
Dim pElement As IElement
Set pElement = pTextElement
pTextElement.Text = "Text in a callout" & vbCrLf & "In the middle of the screen"

Dim dMidX As Double, dMidY As Double
Dim pPoint As IPoint
dMidX = (pMxDoc.ActiveView.Extent.XMax + pMxDoc.ActiveView.Extent.XMin) / 2
dMidY = (pMxDoc.ActiveView.Extent.YMax + pMxDoc.ActiveView.Extent.YMin) / 2
Set pPoint = New Point
pPoint.PutCoords dMidX, dMidY
pElement.Geometry = pPoint

Dim pTextSymbol As IFormattedTextSymbol
Set pTextSymbol = New TextSymbol
Dim pCallout As ICallout
Set pCallout = New BalloonCallout
Set pTextSymbol.Background = pCallout
pPoint.PutCoords dMidX - pMxDoc.ActiveView.Extent.Width / 4, dMidY + pMxDoc.ActiveView.Extent.Width / 20
pCallout.AnchorPoint = pPoint

pTextElement.Symbol = pTextSymbol
Dim pGraphicsContainer As IGraphicsContainer
Set pGraphicsContainer = pMxDoc.ActiveView
pGraphicsContainer.AddElement pElement, 0
pElement.Activate pMxDoc.ActiveView.ScreenDisplay
pMxDoc.ActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing