ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.CIM Namespace / HorizontalAlignment Enumeration
Example Example

In This Topic
    HorizontalAlignment Enumeration
    In This Topic
    Horizontal alignment types.
    Syntax
    Members
    MemberDescription
    Center Centered.
    Justify Justified alignment.
    Left Left aligned.
    Right Right aligned.
    Example
    Modify Annotation Text Graphic
    // Modifies the text graphic of a selected annotation feature in the specified annotation layer.
    await QueuedTask.Run(() =>
    {
      var selection = annotationLayer.GetSelection();
      if (selection.GetCount() == 0)
        return;
      // use the first selected feature 
      var insp = new Inspector();
      insp.Load(annotationLayer, selection.GetObjectIDs().FirstOrDefault());
      // getAnnoProperties should return null if not an annotation feature
      AnnotationProperties annoProperties = insp.GetAnnotationProperties();
      // get the textGraphic
      CIMTextGraphic textGraphic = annoProperties.TextGraphic;
      // change text
      textGraphic.Text = "Hello world";
      // set x,y offset via the symbol
      var symbol = textGraphic.Symbol.Symbol;
      var textSymbol = symbol as CIMTextSymbol;
      textSymbol.OffsetX = 2;
      textSymbol.OffsetY = 3;
      textSymbol.HorizontalAlignment = HorizontalAlignment.Center;
      // load the updated textGraphic
      annoProperties.LoadFromTextGraphic(textGraphic);
      // assign the annotation properties back 
      insp.SetAnnotationProperties(annoProperties);
      EditOperation op = new EditOperation
      {
        Name = "modify symbol"
      };
      op.Modify(insp);
      if (!op.IsEmpty)
      {
        bool result = op.Execute(); //Execute and ExecuteAsync will return true if the operation was successful and false if not
      }
    });
    Annotation Construction Tool
    //In your config.daml...set the categoryRefID
    //<tool id="..." categoryRefID="esri_editing_construction_annotation" caption="Create Anno" ...>
    
    //Sketch type Point or Line or BezierLine in the constructor...
    public class ProSnippetAnnotationConstructionTool : MapTool
    {
      public ProSnippetAnnotationConstructionTool()
      {
        IsSketchTool = true;
        UseSnapping = true;
        SketchType = SketchGeometryType.Point;
      }
    
      /// <summary>
      /// Handles the completion of a sketch operation and creates an annotation feature based on the provided geometry.
      /// </summary>
      protected async override Task<bool> OnSketchCompleteAsync(Geometry geometry)
      {
        if (CurrentTemplate == null || geometry == null)
          return false;
        // Create an edit operation
        var createOperation = new EditOperation
        {
          Name = string.Format("Create {0}", CurrentTemplate.Layer.Name),
          SelectNewFeatures = true
        };
        var insp = CurrentTemplate.Inspector;
        var result = await QueuedTask.Run(() =>
        {
          // get the annotation properties class
          AnnotationProperties annoProperties = insp.GetAnnotationProperties();
          // set custom annotation properties
          annoProperties.TextString = "my custom text";
          annoProperties.Color = ColorFactory.Instance.RedRGB;
          annoProperties.FontSize = 24;
          annoProperties.FontName = "Arial";
          annoProperties.HorizontalAlignment = HorizontalAlignment.Right;
          annoProperties.Shape = geometry;
          // assign annotation properties back to the inspector
          insp.SetAnnotationProperties(annoProperties);
          // Queue feature creation
          createOperation.Create(CurrentTemplate.Layer, insp);
          if (!createOperation.IsEmpty)
          {
            // Execute the operation
            return createOperation.Execute(); //Execute and ExecuteAsync will return true if the operation was successful and false if not
          }
          else
            return false;
        });
        return result;
      }
    }
    Inheritance Hierarchy

    System.Object
       System.ValueType
          System.Enum
             ArcGIS.Core.CIM.HorizontalAlignment

    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also