ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / ElementFactory Class / CreateTextGraphicElement Method
The parent element container
The type of text graphic to create
The geometry for the resulting graphic
The text symbol to be used with the graphic (optional)
The text string (optional)
An element name (optional)
Select after create flag (default is true) (optional)
Additional element properties (optional)
Example

In This Topic
    CreateTextGraphicElement Method (ElementFactory)
    In This Topic
    Creates a text graphic element based on the input geometry, symbol, text and other optional parameters. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Function CreateTextGraphicElement( _
       ByVal elementContainer As IElementContainer, _
       ByVal textType As TextType, _
       ByVal geometry As Geometry, _
       Optional ByVal textSymbol As CIMTextSymbol, _
       Optional ByVal text As String, _
       Optional ByVal elementName As String, _
       Optional ByVal select As Boolean, _
       Optional ByVal elementInfo As ElementInfo _
    ) As GraphicElement

    Parameters

    elementContainer
    The parent element container
    textType
    The type of text graphic to create
    geometry
    The geometry for the resulting graphic
    textSymbol
    The text symbol to be used with the graphic (optional)
    text
    The text string (optional)
    elementName
    An element name (optional)
    select
    Select after create flag (default is true) (optional)
    elementInfo
    Additional element properties (optional)

    Return Value

    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    empty or null geometry
    Remarks
    For:
    • TextType.PointText use a point
    • TextType.SplinedText use a polyline (straight or curved)
    • TextType.CircleParagraph use a circle (polygon) or point
    • TextType.EllipseParagraph use an ellipse (polygon) or point
    • TextType.RectangleParagraph use an envelope or point
    • TextType.PolygonParagraph use a polygon or point
    If a point is used as the input for the paragraph text types, a default element extent is applied.
    Use CreateGraphicElement(IElementContainer,CIMGraphic,String,Boolean,ElementInfo) if you want to use a text graphic previously created, eg via: GraphicFactory.CreateSimpleTextGraphic
    Example
    Create_CurveText
    //Create curve text with basic text properties.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build geometry
      Coordinate2D pt1 = new Coordinate2D(3.6, 7.5);
      Coordinate2D pt2 = new Coordinate2D(4.26, 8);
      Coordinate2D pt3 = new Coordinate2D(4.93, 7.1);
      Coordinate2D pt4 = new Coordinate2D(5.6, 7.5);
      //At 2.x - CubicBezierBuilder bez = new CubicBezierBuilder(pt1, pt2, pt3, pt4);
      var bez = new CubicBezierBuilderEx(pt1, pt2, pt3, pt4);
      CubicBezierSegment bezSeg = bez.ToSegment();
      //At 2.x - Polyline bezPl = PolylineBuilder.CreatePolyline(bezSeg);
      Polyline bezPl = PolylineBuilderEx.CreatePolyline(bezSeg);
    
      //Set symbolology, create and add element to layout
      CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 24, "Comic Sans MS", "Regular");
      //At 2.x - GraphicElement bezTxtElm = LayoutElementFactory.Instance.CreateCurvedTextGraphicElement(layout, bezPl, "Curved Text", sym);
      //         bezTxtElm.SetName("New Splinned Text");
      GraphicElement bezTxtElm = ElementFactory.Instance.CreateTextGraphicElement(
                                    layout, TextType.SplinedText, bezPl, sym, "Curved Text", "New Splinned Text");
    });
    Create_PolygonText
    //Create polygon paragraph text with basic text properties.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build geometry
      List<Coordinate2D> plyCoords = new List<Coordinate2D>();
      plyCoords.Add(new Coordinate2D(3.5, 7));
      plyCoords.Add(new Coordinate2D(4.5, 7));
      plyCoords.Add(new Coordinate2D(4.5, 6.7));
      plyCoords.Add(new Coordinate2D(5.5, 6.7));
      plyCoords.Add(new Coordinate2D(5.5, 6.1));
      plyCoords.Add(new Coordinate2D(3.5, 6.1));
      //At 2.x - Polygon poly = PolygonBuilder.CreatePolygon(plyCoords);
      Polygon poly = PolygonBuilderEx.CreatePolygon(plyCoords);
    
      //Set symbolology, create and add element to layout
      CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.GreyRGB, 10, "Arial", "Regular");
      string text = "Some Text String that is really long and is <BOL>forced to wrap to other lines</BOL> so that we can see the effects." as String;
      //At 2.x - GraphicElement polyTxtElm = LayoutElementFactory.Instance.CreatePolygonParagraphGraphicElement(layout, poly, text, sym);
      //         polyTxtElm.SetName("New Polygon Text"); 
      GraphicElement polyTxtElm = ElementFactory.Instance.CreateTextGraphicElement(
                                    layout, TextType.RectangleParagraph, poly, sym, text, "New Polygon Text");
    
      //(Optionally) Modify paragraph border 
      CIMGraphic polyTxtGra = polyTxtElm.GetGraphic();
      CIMParagraphTextGraphic cimPolyTxtGra = polyTxtGra as CIMParagraphTextGraphic;
      cimPolyTxtGra.Frame.BorderSymbol = new CIMSymbolReference();
      cimPolyTxtGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid);
      polyTxtElm.SetGraphic(polyTxtGra);
    });
    
    Create_CircleText
    //Create circle paragraph text with basic text settings and optionally a modified border.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build geometry
      Coordinate2D center = new Coordinate2D(4.5, 4);
      //At 2.x - EllipticArcBuilder eabCir = new EllipticArcBuilder(center, 0.5, esriArcOrientation.esriArcClockwise);
      var eabCir = new EllipticArcBuilderEx(center, 0.5, ArcOrientation.ArcClockwise);
      EllipticArcSegment cir = eabCir.ToSegment();
      var polyCir = PolygonBuilderEx.CreatePolygon(
                      PolylineBuilderEx.CreatePolyline(cir));
    
      //Set symbolology, create and add element to layout
      CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.GreenRGB, 10, "Arial", "Regular");
      string text = "Circle, circle, circle, circle, circle, circle, circle, circle, circle, circle, circle";
      //At 2.x - GraphicElement cirTxtElm = LayoutElementFactory.Instance.CreateCircleParagraphGraphicElement(layout, cir, text, sym);
      //         cirTxtElm.SetName("New Circle Text");
      GraphicElement cirTxtElm = ElementFactory.Instance.CreateTextGraphicElement(
                                    layout, TextType.CircleParagraph, polyCir, sym, text, "New Circle Text");
    
      //(Optionally) Modify paragraph border 
      CIMGraphic cirTxtGra = cirTxtElm.GetGraphic();
      CIMParagraphTextGraphic cimCirTxtGra = cirTxtGra as CIMParagraphTextGraphic;
      cimCirTxtGra.Frame.BorderSymbol = new CIMSymbolReference();
      cimCirTxtGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid);
      cirTxtElm.SetGraphic(cirTxtGra);
    });
    Create_EllipseText
    //Create ellipse paragraph text with basic text settings and optionally a modified border.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build geometry
      Coordinate2D center = new Coordinate2D(4.5, 2.75);
      //At 2.x - EllipticArcBuilder eabElp = new EllipticArcBuilder(center, 0, 1, 0.45, esriArcOrientation.esriArcClockwise);
      var eabElp = new EllipticArcBuilderEx(center, 0, 1, 0.45, ArcOrientation.ArcClockwise);
      EllipticArcSegment ellipse = eabElp.ToSegment();
      var polyElp = PolygonBuilderEx.CreatePolygon(
                      PolylineBuilderEx.CreatePolyline(ellipse));
    
      //Set symbolology, create and add element to layout
      CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlueRGB, 10, "Arial", "Regular");
      string text = "Ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse, ellipse";
      //At 2.x - GraphicElement elpTxtElm = LayoutElementFactory.Instance.CreateEllipseParagraphGraphicElement(layout, ellipse, text, sym);
      //         elpTxtElm.SetName("New Ellipse Text");
      GraphicElement elpTxtElm = ElementFactory.Instance.CreateTextGraphicElement(
                                    layout, TextType.EllipseParagraph, polyElp, sym, text, "New Ellipse Text");
    
      //(Optionally) Modify paragraph border 
      CIMGraphic elpTxtGra = elpTxtElm.GetGraphic();
      CIMParagraphTextGraphic cimElpTxtGra = elpTxtGra as CIMParagraphTextGraphic;
      cimElpTxtGra.Frame.BorderSymbol = new CIMSymbolReference();
      cimElpTxtGra.Frame.BorderSymbol.Symbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid);
      elpTxtElm.SetGraphic(elpTxtGra);
    });
    Create Point Text Element 1
    //Create a simple point text element and assign basic symbology and text settings.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build 2D point geometry
      Coordinate2D coord2D = new Coordinate2D(3.5, 10);
    
      //Set symbolology, create and add element to layout
      CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(
                    ColorFactory.Instance.RedRGB, 32, "Arial", "Regular");
      string textString = "Point text";
      //At 2.x - GraphicElement ptTxtElm =
      //         LayoutElementFactory.Instance.CreatePointTextGraphicElement(
      //                           layout, coord2D, textString, sym);
      //ptTxtElm.SetName("New Point Text");
      //ptTxtElm.SetAnchor(Anchor.CenterPoint);
      //ptTxtElm.SetX(4.5);
      //ptTxtElm.SetY(9.5);
      //ptTxtElm.SetRotation(45);
    
      //use ElementInfo to set placement properties during create
      var elemInfo = new ElementInfo()
      {
        Anchor = Anchor.CenterPoint,
        Rotation = 45
      };
      var ptTxtElm = ElementFactory.Instance.CreateTextGraphicElement(
        container, TextType.PointText, coord2D.ToMapPoint(), sym, textString,
                           "New Point Text", true, elemInfo);
    
      //Change additional text properties
      ptTxtElm.SetX(4.5);
      ptTxtElm.SetY(9.5);
    });
    Create Rectangle Paragraph Text Element 1
    //Create rectangle text with background and border symbology.  
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build 2D polygon geometry
      List<Coordinate2D> plyCoords = new List<Coordinate2D>();
      plyCoords.Add(new Coordinate2D(3.5, 7));
      plyCoords.Add(new Coordinate2D(4.5, 7));
      plyCoords.Add(new Coordinate2D(4.5, 6.7));
      plyCoords.Add(new Coordinate2D(5.5, 6.7));
      plyCoords.Add(new Coordinate2D(5.5, 6.1));
      plyCoords.Add(new Coordinate2D(3.5, 6.1));
      //At 2.x - Polygon poly = PolygonBuilder.CreatePolygon(plyCoords);
      Polygon poly = PolygonBuilderEx.CreatePolygon(plyCoords);
    
      //Set symbolology, create and add element to layout
      //Also notice how formatting tags are using within the text string.
      CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(
                        ColorFactory.Instance.GreyRGB, 10, "Arial", "Regular");
      string text = "Some Text String that is really long and is " +
                    "<BOL>forced to wrap to other lines</BOL> so that " +
                    "we can see the effects." as String;
      //At 2.x - GraphicElement polyTxtElm =
      //           LayoutElementFactory.Instance.CreatePolygonParagraphGraphicElement(
      //                                      layout, poly, text, sym);
      //         polyTxtElm.SetName("New Polygon Text");
    
      GraphicElement polyTxtElm = ElementFactory.Instance.CreateTextGraphicElement(
        container, TextType.RectangleParagraph, poly, sym, text, "Polygon Paragraph");
    
      //(Optionally) Modify paragraph border 
      CIMGraphic polyTxtGra = polyTxtElm.GetGraphic();
      CIMParagraphTextGraphic cimPolyTxtGra = polyTxtGra as CIMParagraphTextGraphic;
      cimPolyTxtGra.Frame.BorderSymbol = new CIMSymbolReference();
      cimPolyTxtGra.Frame.BorderSymbol.Symbol =
                   SymbolFactory.Instance.ConstructLineSymbol(
                              ColorFactory.Instance.GreyRGB, 1.0, SimpleLineStyle.Solid);
      polyTxtElm.SetGraphic(polyTxtGra);
    });
    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()) as TextElement;
    
      //Modify the text properties
      titleGraphics.SetTextProperties(new TextProperties(title, "Arial", 24, "Bold"));
    });
    Create Point Text Element 2
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    Coordinate2D coord2D = new Coordinate2D(3.5, 10);
    
    //Set symbolology, create and add element to layout
    CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(
      ColorFactory.Instance.RedRGB, 32, "Arial", "Regular");
    string textString = "Point text";
    
    var elemInfo = new ElementInfo() { Anchor = Anchor.BottomLeftCorner };
    GraphicElement ptTxtElm = ElementFactory.Instance.CreateTextGraphicElement(
      container, TextType.PointText, coord2D.ToMapPoint(), sym, textString,
      "New Point Text", true, elemInfo);
    
    Create Polygon Paragraph Text Element
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    List<Coordinate2D> plyCoords = new List<Coordinate2D>();
    plyCoords.Add(new Coordinate2D(3.5, 7));
    plyCoords.Add(new Coordinate2D(4.5, 7));
    plyCoords.Add(new Coordinate2D(4.5, 6.7));
    plyCoords.Add(new Coordinate2D(5.5, 6.7));
    plyCoords.Add(new Coordinate2D(5.5, 6.1));
    plyCoords.Add(new Coordinate2D(3.5, 6.1));
    Polygon poly = PolygonBuilderEx.CreatePolygon(plyCoords);
    
    //Set symbolology, create and add element to layout
    CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(
         ColorFactory.Instance.GreyRGB, 10, "Arial", "Regular");
    string text = "Some text string that is really long and " +
                  "<BOL>wraps to other lines</BOL>" +
                  " so that we can see the effects.";
    
    var ge = ElementFactory.Instance.CreateTextGraphicElement(
      container, TextType.PolygonParagraph, poly, sym, text,
            "New Polygon Text", true);
    Create Rectangle Paragraph Text Element 2
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    Coordinate2D ll = new Coordinate2D(3.5, 4.75);
    Coordinate2D ur = new Coordinate2D(5.5, 5.75);
    Envelope env = EnvelopeBuilderEx.CreateEnvelope(ll, ur);
    
    //Set symbolology, create and add element to layout
    CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(
               ColorFactory.Instance.WhiteRGB, 10, "Arial", "Regular");
    string text = "Some text string that is really long and " +
                  "<BOL>wraps to other lines</BOL>" +
                  " so that we can see the effects.";
    
    //(Optionally) Modify border and background with 50% transparency 
    //CIMGraphic recTxtGra = recTxtElm.Graphic;
    //CIMParagraphTextGraphic cimRecTxtGra = recTxtGra as CIMParagraphTextGraphic;
    //CIMSymbolReference cimRecTxtBorder = cimRecTxtGra.Frame.BorderSymbol;
    //
    //CIMLineSymbol lineSym = SymbolFactory.Instance.ConstructLineSymbol(
    //                    ColorFactory.Instance.BlackRGB, 1.0, SimpleLineStyle.Solid);
    //cimRecTxtBorder.Symbol = lineSym;
    //
    //CIMSymbolReference cimRecTxtBkgrd = cimRecTxtGra.Frame.BackgroundSymbol;
    //CIMPolygonSymbol polySym = SymbolFactory.Instance.ConstructPolygonSymbol(
    //                            ColorFactory.Instance.GreyRGB, SimpleFillStyle.Solid);
    //
    //CIMColor symCol = polySym.GetColor(IElementContainer container);
    //symCol.SetAlphaValue(50);
    //cimRecTxtBkgrd.Symbol = polySym;
    //recTxtElm.SetGraphic(recTxtGra);
    
    var ge = ElementFactory.Instance.CreateTextGraphicElement(container,
                TextType.RectangleParagraph, env, sym, text, "New Rectangle Text");
    Create Circle Text Element
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    Coordinate2D center = new Coordinate2D(4.5, 4);
    var eabCir = new EllipticArcBuilderEx(center, 0.5, ArcOrientation.ArcClockwise);
    var cir = eabCir.ToSegment();
    
    var poly = PolygonBuilderEx.CreatePolygon(
      PolylineBuilderEx.CreatePolyline(cir, AttributeFlags.AllAttributes));
    
    //Set symbolology, create and add element to layout
    CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(
                    ColorFactory.Instance.GreenRGB, 10, "Arial", "Regular");
    string text = "Circle, circle, circle";
    
    GraphicElement cirTxtElm = ElementFactory.Instance.CreateTextGraphicElement(
      container, TextType.CircleParagraph, poly, sym, text, "New Circle Text", false);
    
    Create Bezier Text Element
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    Coordinate2D pt1 = new Coordinate2D(3.5, 7.5);
    Coordinate2D pt2 = new Coordinate2D(4.16, 8);
    Coordinate2D pt3 = new Coordinate2D(4.83, 7.1);
    Coordinate2D pt4 = new Coordinate2D(5.5, 7.5);
    var bez = new CubicBezierBuilderEx(pt1, pt2, pt3, pt4);
    var bezSeg = bez.ToSegment();
    Polyline bezPl = PolylineBuilderEx.CreatePolyline(bezSeg, AttributeFlags.AllAttributes);
    
    //Set symbolology, create and add element to layout
    CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(
      ColorFactory.Instance.BlackRGB, 24, "Comic Sans MS", "Regular");
    
    var ge = ElementFactory.Instance.CreateTextGraphicElement(
      container, TextType.SplinedText, bezPl, sym, "this is the bezier text",
            "New Bezier Text", true, new ElementInfo() { Anchor = Anchor.CenterPoint });
    
    Create Ellipse Text Element
    //Must be on QueuedTask.Run(() => { ...
    
    //Build geometry
    Coordinate2D center = new Coordinate2D(4.5, 2.75);
    var eabElp = new EllipticArcBuilderEx(center, 0, 1, 0.45, ArcOrientation.ArcClockwise);
    var ellipse = eabElp.ToSegment();
    
    var poly = PolygonBuilderEx.CreatePolygon(
      PolylineBuilderEx.CreatePolyline(ellipse, AttributeFlags.AllAttributes));
    
    //Set symbolology, create and add element to layout
    CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(
                          ColorFactory.Instance.BlueRGB, 10, "Arial", "Regular");
    string text = "Ellipse, ellipse, ellipse";
    
    GraphicElement ge = ElementFactory.Instance.CreateTextGraphicElement(
      container, TextType.PolygonParagraph, poly, sym, text, "New Ellipse Text", false);
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also