ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / TextElement Class
Members Example Version

TextElement Class
Represents a text element on a page layout.
Object Model
TextElement ClassGraphicElement ClassCoordinate2D StructureEnvelope ClassCIMElement ClassGeometry ClassCIMGraphic ClassIElementContainer InterfaceTextProperties Class
Syntax
Remarks
The TextElement class represents text elements on a page layout. This includes items such as inserted point text, rectangle text, and so on. It can also include text elements that are part of a group element but it does not include text that is part of a legend, scale bar or other map surround items.
Example
TextElement_SetTextProperties
await QueuedTask.Run(() =>
{
  TextElement txtElm = layout.FindElement("Text") as TextElement;
  txtElm.SetTextProperties(txtProp);
});
      
Create a Dynamic Point Text Element
//Create a dynamic text element.

//Set the string with tags and the location
String title = @"<dyn type = ""page"" property = ""name"" />";
Coordinate2D llTitle = new Coordinate2D(6, 2.5);

//Construct element on worker thread
await QueuedTask.Run(() =>
{
  //Create with default text properties
  //At 2.x - TextElement titleGraphics =
  //          LayoutElementFactory.Instance.CreatePointTextGraphicElement(
  //                                  layout, llTitle, null) as TextElement;
  TextElement titleGraphics = ElementFactory.Instance.CreateTextGraphicElement(
                container, TextType.PointText, llTitle.ToMapPoint(), null, title) as TextElement;

  //Modify the text properties
  titleGraphics.SetTextProperties(new TextProperties(title, "Arial", 24, "Bold"));
});
Update text element properties
//Update text element properties for an existing text element.

// Reference a layoutitem in a project by name
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>()
                      .FirstOrDefault(item => item.Name.Equals("MyLayout"));
if (layoutItem != null)
{

  //Perform on the worker thread
  QueuedTask.Run(() =>
  {
    // Reference and load the layout associated with the layout item
    Layout layout = layoutItem.GetLayout();
    if (layout != null)
    {
      // Reference a text element by name
      TextElement txtElm = layout.FindElement("MyTextElement") as TextElement;
      if (txtElm != null)
      {
        // Change placement properties
        txtElm.SetAnchor(Anchor.CenterPoint);
        txtElm.SetX(x);
        txtElm.SetY(y);

        // Change TextProperties
        TextProperties txtProperties = new TextProperties(
                         "Hello world", "Times New Roman", 48, "Regular");
        txtElm.SetTextProperties(txtProperties);
      }
    }
  });
}
Modify existing text element properties
//Modify the text properties for an existing text element.

//Reference a layoutitem in a project by name
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Layout"));

//Perform on the worker thread
await QueuedTask.Run(() =>
{
  //Reference and load the layout associated with the layout item
  Layout lyt = layoutItem.GetLayout();

  //Reference a text element by name
  TextElement txtElm = lyt.FindElement("Title") as TextElement;

  //Change placement
  txtElm.SetX(4.25);
  txtElm.SetY(8);

  //Change TextProperties
  TextProperties txt_prop = txtElm.TextProperties;
  txt_prop.FontSize = 48;
  txt_prop.Font = "Times New Roman";
  txt_prop.Text = "Some new text";
  txtElm.SetTextProperties(txt_prop);
});
Modify existing text properties
//Modify the text properties for an existing text element.

//Reference a layoutitem in a project by name
LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("Layout"));

//Perform on the worker thread
await QueuedTask.Run(() =>
{
  //Reference and load the layout associated with the layout item
  Layout lyt = layoutItem.GetLayout();

  //Reference a text element by name
  TextElement txtElm = lyt.FindElement("Title") as TextElement;

  //Change placement
  txtElm.SetX(4.25);
  txtElm.SetY(8);

  //Change TextProperties
  TextProperties txt_prop = txtElm.TextProperties;
  txt_prop.FontSize = 48;
  txt_prop.Font = "Times New Roman";
  txt_prop.Text = "Some new text";
  txtElm.SetTextProperties(txt_prop);
});
Inheritance Hierarchy

System.Object
   ArcGIS.Desktop.Framework.Contracts.PropertyChangedBase
      ArcGIS.Desktop.Layouts.Element
         ArcGIS.Desktop.Layouts.GraphicElement
            ArcGIS.Desktop.Layouts.TextElement

Requirements

Target Platforms: Windows 11, Windows 10

ArcGIS Pro version: 3 or higher.
See Also