Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to add a white halo to labels using arcobjects. I think I need to reference the IFormattedTextSymbol interface, but I'm not sure how to implement this into my current code (see below). Thank you for your help.

Dim pDoc As IMxDocument
Set pDoc = ThisDocument
Set pMap = pDoc.FocusMap
' Get the selected layer
Dim pLayer As IGeoFeatureLayer
Set pLayer = pMap.Layer(0)

Dim pFc As IFeatureClass
Dim strOIDName As String
Set pFc = pLayer.FeatureClass
strOIDName = pFc.OIDFieldName

' Get the selected features from the layer
Dim pFSel As IFeatureSelection
Set pFSel = pLayer
Dim pSelSet As ISelectionSet
Set pSelSet = pFSel.SelectionSet
Dim pFCur As IFeatureCursor
pSelSet.Search Nothing, False, pFCur

' Loop through the selected features and create a label
' expression for the selected features

Dim pFeat As IFeature
Dim strSql As String
Set pFeat = pFCur.NextFeature

Do While Not pFeat Is Nothing
   If strSql = "" Then
     strSql = strOIDName & " = " & pFeat.OID
     strSql = strSql & " or " & strOIDName & " = " & pFeat.OID
   End If
   Set pFeat = pFCur.NextFeature
Debug.Print strSql

' Get AnnotateLayerPropertiesCollection from layer
Dim pAnnoLayerPropsColl As IAnnotateLayerPropertiesCollection
Set pAnnoLayerPropsColl = pLayer.AnnotationProperties
Dim pAnnoLayerProps As IAnnotateLayerProperties
pAnnoLayerPropsColl.QueryItem 0, pAnnoLayerProps, Nothing, Nothing
pAnnoLayerProps.Class = "LabelSel"
pAnnoLayerProps.WhereClause = strSql
Dim aAnnoVBScriptEngine As IAnnotationExpressionEngine
Set aAnnoVBScriptEngine = New AnnotationVBScriptEngine

Dim pTextsymbol As ITextSymbol
Set pTextsymbol = New TextSymbol

Dim pFont As IFontDisp
Set pFont = pTextsymbol.font

Dim pFormattedtxtsym As IFormattedTextSymbol
pFormattedtxtsym.ShadowColor = True

pFont.Bold = True
pFont.size = 10
pFont.Weight = 2
pTextsymbol.font = pFont

Dim pLELayerProps As ILabelEngineLayerProperties
Set pLELayerProps = pAnnoLayerProps
Set pLELayerProps.ExpressionParser = aAnnoVBScriptEngine

pLELayerProps.Expression = "[Longlabel] & vbnewline & [Latlabel] & vbnewline & [Elevlabel] & _ vbnewline &[Driftlabel]"

Set pLELayerProps.Symbol = pTextsymbol

' Display the lables
pLayer.DisplayAnnotation = True
' Refresh the Data Frame
share|improve this question
up vote 6 down vote accepted

Halos are specified through the IMask interface which the TextSymbol class implements:

Dim pMask As IMask
Dim pMaskFillSymbol As IFillSymbol
Dim pMaskFillColor As IRgbColor

Set pMask = pTextSymbol ' your textsymbol
pMask.MaskStyle = esriMSHalo
pMask.MaskSize = 1  ' halo size

' red halo around text, modify to your desired color
Set pMaskFillSymbol = New SimpleFillSymbol
Set pMaskFillColor = New RgbColor
pMaskFillColor.Red = 255
pMaskFillColor.Green = 0
pMaskFillColor.Blue = 0
pMaskFillSymbol.Color = pMaskFillColor

Set pMask.MaskSymbol = pMaskFillSymbol
share|improve this answer
Thanks for your reply. I updated my code. The halo properties are updated now however the label/annotation is not updating. – artwork21 Jan 19 '11 at 17:38
I updated the code slightly (the Dim declarations were missing). – Petr Krebs Jan 19 '11 at 17:47
Not sure what the problem is though. I used your code exactly to every line with only few changes (got rid of IFormattedTextSymbol, added the above snippet after the initialization of the text symbol, changed the label expression to different fields) and works fine.. – Petr Krebs Jan 19 '11 at 17:50
I saved the mxd and closed it, and opened it again and it worked fine. To make the halo outlinewidth 0, do I need to use the ISimpleLineSymbol interphase? Right now the outlinewidth is grey at 1. – artwork21 Jan 19 '11 at 18:42
If you do not want the outline, try pMaskFillSymbol.Outline = Nothing, that should reset it to a non-visible line, without the need to work with the line symbol explicitly. – Petr Krebs Jan 19 '11 at 18:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.