1

I originally posted this query on the ESRI forums but thought I may get more help here.

I have cobbled together some code to set halos around text labels for a given feature layer in ArcMap. The problem I'm having is having the newly formatted labels updated in the display afterwards. The usual IDocument.ActiveView.Refresh doesn't work.

So far the code below does make the necessary changes in the label properties but any type of refresh code doesn't make the changes in the display view. The only way to do it is open up the properties, toggle something to get the 'Apply' button activated, then press Apply. I ran code and only toggled the IGeoFeatureLayer.DisplayAnnotation and it worked fine with the usual ActiveView.Refresh method. This leads me to think that something is not being set or updated correctly in the ILabelEngineLayerProperties properties before being added to the IAnnotateLayerPropertiesCollection at the end. Any suggestions out there?

ArcGIS 10.3; Windows 7; VS Express 2013

   public void add_halo(IGeoFeatureLayer fl)
   {
    IAnnotateLayerPropertiesCollection pAnno = fl.AnnotationProperties;
    pAnno.Clear();
    IAnnotateLayerProperties labelEngineProperties = new LabelEngineLayerProperties() as IAnnotateLayerProperties;
    ILabelEngineLayerProperties pLprop = labelEngineProperties as ILabelEngineLayerProperties;
    ITextSymbol pTextSymbol = pLprop.Symbol;
    IFillSymbol pMaskFillSymbol;
    IRgbColor pMaskFillColor;
    IMask pMask = (IMask)pTextSymbol;
    pMask.MaskStyle = esriMaskStyle.esriMSHalo;
    pMask.MaskSize = 2; //  ' halo size;

    pMaskFillSymbol = new SimpleFillSymbol();
    pMaskFillColor = new RgbColor();
    pMaskFillColor.Red = 255;
    pMaskFillColor.Green = 255;
    pMaskFillColor.Blue = 255;
    pMaskFillSymbol.Color = pMaskFillColor;
    pMaskFillSymbol.Outline = null;
    pMask.MaskSymbol = pMaskFillSymbol;

    pTextSymbol.Size = 10;
    pAnno.Add((IAnnotateLayerProperties)pLprop);

    fl.DisplayAnnotation = true;
}
  • Are you calling this sub between instances of StartDrawing and StopDrawing? – Michael Stimson Jun 10 '16 at 3:36
  • No I wasn't using IDisplay but after trying I still had no fix. I used code IDraw pDraw = (IDraw)pDoc.ActiveView.ScreenDisplay; pDraw.StartDrawing(0, (short)esriScreenCache.esriNoScreenCache); add_halo(fl); pDraw.FinishDrawing(); – adriank Jun 13 '16 at 23:34
  • You said "The usual IDocument.ActiveView.Refresh doesn't work" have you tried accessing the ActiveView frorm IMXDocument? – Hornbydd Jun 14 '16 at 15:33
  • @Hornbydd - Yes I have been using IMXDocument. I should have written that in the original text. – adriank Jun 14 '16 at 22:32
1

I had a fix posted on the ESRI forum by Jeff Matson which I'll put here. Basically I shouldn't be creating a new LabelEngineLayerProperties object. I can get it by querying the AnnotateLayerPropertiesCollection. There should be no need to clear and re-add it

Here is the working code:

        public void add_halo(IGeoFeatureLayer fl)
    {

        fl.DisplayAnnotation = false;
        pDoc.ActiveView.Refresh();

        IElementCollection ec1;
        IElementCollection ec2;

        IAnnotateLayerPropertiesCollection pAnno = fl.AnnotationProperties;
        IAnnotateLayerProperties alp;
        pAnno.QueryItem(0, out alp, out ec1, out ec2); //     'query first anno class

        IAnnotateLayerProperties labelEngineProperties = alp; // new LabelEngineLayerProperties() as IAnnotateLayerProperties;
        ILabelEngineLayerProperties pLprop = labelEngineProperties as ILabelEngineLayerProperties;

        ITextSymbol pTextSymbol = pLprop.Symbol;
        IFillSymbol pMaskFillSymbol; 
        IRgbColor pMaskFillColor; 

        IMask pMask = (IMask)pTextSymbol; 
        pMask.MaskStyle = esriMaskStyle.esriMSHalo; 
        pMask.MaskSize = 2; //  ' halo size;

        pMaskFillSymbol = new SimpleFillSymbol();
        pMaskFillColor = new RgbColor();
        pMaskFillColor.Red = 255;
        pMaskFillColor.Green = 255;
        pMaskFillColor.Blue = 255;
        pMaskFillSymbol.Color = pMaskFillColor;
        pMaskFillSymbol.Outline = null;
        pMask.MaskSymbol = pMaskFillSymbol;

        pTextSymbol.Size = 10;
        fl.AnnotationProperties = pAnno;

        fl.DisplayAnnotation = true;

        fl = null;

    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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