I am trying to display annotations for single features. I know it is possible to display annotations for layers, and for that entire map, but I would like to display them based on a SINGLE selected feature. example:-

I have a layer called A that is visible on the map, so all the features in it are visible. Now I select a feature, and want to display the annotation for that particular feature not the whole layer; how is this possible?

In my code I am doing this but for the entire layer, but I want it for a single feature, any ideas?

Here is my code which is a method that displays annotations for STRUCTURE features:

public static void ToggleXyLabelVisibility(IApplication application,ISchematicLayer layer, ISchematicFeature slctdFtr =null) {
        var doc = application.Document as IMxDocument;
        if (doc != null) {
      // display annotation for the entire layer if no features are selected
            if (slctdFtr == null) {
                var compLayer = layer as ICompositeLayer;
                if (compLayer != null) {
                    for (int i = 0; i < compLayer.Count; i++) {
                        var geoflay = compLayer.Layer[i] as IGeoFeatureLayer;
                        if (geoflay != null) {
                            for (int j = 0; j < geoflay.AnnotationProperties.Count; j++) {
                                var annotationProperties = geoflay.AnnotationProperties;
                                IElementCollection col1;
                                IElementCollection col2;
                                IAnnotateLayerProperties properties;
                                annotationProperties.QueryItem(j, out properties, out col1, out col2);
                                if (string.Equals(properties.Class, Locationlabel,
                                    StringComparison.CurrentCultureIgnoreCase)) {
                                    properties.DisplayAnnotation = !properties.DisplayAnnotation;

            // if features are selected, then display it for those selected features only
            else {
  • 1
    Did you try setting IAnnotateLayerProperties.LabelWhichFeatures to esriSelectedFeatures ? Jun 3, 2015 at 15:57
  • here is what I did if (string.Equals(properties.Class, Locationlabel, StringComparison.CurrentCultureIgnoreCase)) { if(slctStr !=null) properties.LabelWhichFeatures=esriWhichFeature.esriSelectedFeatures properties.DisplayAnnotation = !properties.DisplayAnnotation; } But nothing changes, it applies to all the features not the selected ones
    – ZZZ
    Jun 4, 2015 at 13:15

1 Answer 1


Set IAnnotateLayerProperties.LabelWhichFeatures to esriSelectedFeatures Try this!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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