ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / SymbolFactory Class / ConstructTextSymbol Method / ConstructTextSymbol(CIMColor,Double,String) Method
ArcGIS.Core.CIM.CIMColor
The size of the text symbol to construct.
The font family name of the text symbol to construct.
Example

In This Topic
    ConstructTextSymbol(CIMColor,Double,String) Method
    In This Topic
    Constructs a default text symbol given its color, size, and font family name. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Overloads Function ConstructTextSymbol( _
       ByVal color As CIMColor, _
       ByVal size As Double, _
       ByVal fontFamilyName As String _
    ) As CIMTextSymbol
    public CIMTextSymbol ConstructTextSymbol( 
       CIMColor color,
       double size,
       string fontFamilyName
    )

    Parameters

    color
    ArcGIS.Core.CIM.CIMColor
    size
    The size of the text symbol to construct.
    fontFamilyName
    The font family name of the text symbol to construct.

    Return Value

    Exceptions
    ExceptionDescription
    This method must be called within the lambda passed to QueuedTask.Run
    Remarks
    If the font family is null or does not exist the current default font family will be assigned. The default font style for the font family will be assigned.
    Example
    Create Point Text Element 1
    {
      //Create a simple point text element and assign basic symbology and text settings.
    
      //Note: Must be on QueuedTask.Run
      //Build 2D point geometry
      Coordinate2D coord2D = new Coordinate2D(3.5, 10);
    
      //Set symbology, create and add element to layout
      CIMTextSymbol sym = SymbolFactory.Instance.ConstructTextSymbol(
                    ColorFactory.Instance.RedRGB, 32, "Arial", "Regular");
      string textString = "Point text";
    
      //use ElementInfo to set placement properties during create
      var elemInfo = new ElementInfo()
      {
        Anchor = Anchor.CenterPoint,
        Rotation = 45
      };
      var ptTxtElm = ElementFactory.Instance.CreateTextGraphicElement(
        layout, 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
    {
      //Note: Must be on QueuedTask.Run
      //Create rectangle text with background and border symbology.  
      //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));
      Polygon poly = PolygonBuilderEx.CreatePolygon(plyCoords);
    
      //Set symbology, 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;
    
      GraphicElement polyTxtElm = ElementFactory.Instance.CreateTextGraphicElement(
        layout, 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);
    }
    Construct a Text Symbol With Options
    {
        //Note: Needs QueuedTask to run
        //using the default font
        var textSym1 = SymbolFactory.Instance.ConstructTextSymbol();
        var textSym2 = SymbolFactory.Instance.ConstructTextSymbol(
                           ColorFactory.Instance.BlueRGB, 14);
    
        //using a specific font
        var textSym3 = SymbolFactory.Instance.ConstructTextSymbol("Arial");
        var textSym4 = SymbolFactory.Instance.ConstructTextSymbol(
                          "Arial", "Narrow Bold");
    
        //or query available fonts to ensure the font is there
        var all_fonts = SymbolFactory.Instance.GetAvailableFonts();
        var font = all_fonts.FirstOrDefault(f => f.fontName == "Arial");
        if (!string.IsNullOrEmpty(font.fontName))
        {
            var textSym5 = SymbolFactory.Instance.ConstructTextSymbol(font.fontName);
            //or with a font+style
            var textSym6 = SymbolFactory.Instance.ConstructTextSymbol(
                                            font.fontName, font.fontStyles.First());
        }
    
        //overloads - font + color and size, etc
        var textSym7 = SymbolFactory.Instance.ConstructTextSymbol(
                        ColorFactory.Instance.BlueRGB, 14, "Times New Roman", "Italic");
    
        //custom symbol - black stroke, red fill
        var poly_symbol = SymbolFactory.Instance.ConstructPolygonSymbol(
          SymbolFactory.Instance.ConstructSolidFill(ColorFactory.Instance.RedRGB),
          SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 1));
        var textSym8 = SymbolFactory.Instance.ConstructTextSymbol(
                poly_symbol, 14, "Georgia", "Bold");
    }
    Creates a simple text symbol
    /// <summary>
    ///  Creates a simple black text symbol with a size of 8.5, Font Family "Corbel" and Font Style of "Regular".
    /// ![lineCallOut](https://ArcGIS.github.io/arcgis-pro-sdk/images/Labeling/SimpleText.png)
    /// </summary>
    {
      //Create a simple text symbol
      //Note: Run this code inside a QueuedTask
      CIMTextSymbol simpleTextSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 8.5, "Corbel", "Regular");
      //Refer to the snippet "How to apply a Text Symbol to labels of a layer" below to see how to apply this text symbol to a label class
    }
    Snippet Creates a text symbol with a halo
    /// <summary>
    /// Creates a text symbol with a red halo
    /// ![halo](https://ArcGIS.github.io/arcgis-pro-sdk/images/Labeling/halo.png)
    /// </summary>
    {
      //create a polygon symbol for the halo
      //Note: Run this code inside a QueuedTask
      var haloPoly = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.Solid);
      //create text symbol using the halo polygon
      CIMTextSymbol textSymbolWithHalo = SymbolFactory.Instance.ConstructTextSymbol(haloPoly, 10, "Arial", "Bold");
      //Refer to the snippet "How to apply a Text Symbol to labels of a layer" below to see how to apply this text symbol to a label class
    
    }
    Snippet Creates a simple line callout text symbol
    /// <summary>
    /// Creates a simple line callout text symbol.  The [CIMSimpleLineCallout](https://pro.arcgis.com/en/pro-app/sdk/api-reference/#topic2760.html) created is a dash-dot-dash line symbol with an offset of 10 from the geometry being labeled.
    /// ![lineCallOut](https://ArcGIS.github.io/arcgis-pro-sdk/images/Labeling/line-callout.png)
    /// </summary>
    {
      //create a text symbol
      //Note: Run this code inside a QueuedTask
      var textSymbolCallOut = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 10, "Verdana", "Regular");
      //Create a line call out
      var lineCalloutSymbol = new CIMSimpleLineCallout();
      //Get a line symbol
      var lineSymbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 1, SimpleLineStyle.DashDotDot);
      //assign the line symbol to the callout
      lineCalloutSymbol.LineSymbol = lineSymbol;
      //Offset for the text
      textSymbolCallOut.OffsetX = 10;
      textSymbolCallOut.OffsetY = 10;
      //Assign the callout to the text symbol
      textSymbolCallOut.Callout = lineCalloutSymbol;
    
      //Refer to the snippet "How to apply a Text Symbol to labels of a layer" below to see how to apply this text symbol to a label class
    }
    Snippet Creates a balloon callout text symbol
    /// <summary>
    /// Creates a black banner balloon callout text symbol. The [CIMBalloonCallout](https://pro.arcgis.com/en/pro-app/sdk/api-reference/#topic487.html) created is a rectangular polygon with rounded corners.
    /// ![lineCallOut](https://ArcGIS.github.io/arcgis-pro-sdk/images/Labeling/banner-callout.png)
    /// </summary>
    {
      //create a text symbol
      //Note: Run this code inside a QueuedTask
      var textSymbolBalloonCallout = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.WhiteRGB, 11, "Corbel", "Regular");
      //A balloon callout
      var balloonCallout = new CIMBalloonCallout();
      //set the callout's style
      balloonCallout.BalloonStyle = BalloonCalloutStyle.RoundedRectangle;
      //Create a solid fill polygon symbol for the callout.
      var polySymbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.BlackRGB, SimpleFillStyle.Solid);
      //Set the callout's background to be the black polygon symbol
      balloonCallout.BackgroundSymbol = polySymbol;
      //margin inside the callout to place the text
      balloonCallout.Margin = new CIMTextMargin
      {
        Left = 5,
        Right = 5,
        Bottom = 5,
        Top = 5
      };
      //assign the callout to the text symbol's callout property
      textSymbolBalloonCallout.Callout = balloonCallout;
      //Refer to the snippet "How to apply a Text Symbol to labels of a layer" below to see how to apply this text symbol to a label class
    }
    Snippet Creates a point callout text symbol
    /// <summary>
    /// Creates a highway shield callout text symbol. The [CIMPointSymbolCallout](https://pro.arcgis.com/en/pro-app/sdk/api-reference/#topic4116.html) created is a highway shield point symbol from the ArcGIS 2D style.
    /// ![lineCallOut](https://ArcGIS.github.io/arcgis-pro-sdk/images/Labeling/highway-callout.png)
    /// </summary>
    {
      //create a text symbol
      //Note: Run this code inside a QueuedTask
      var textSymbolPointCallout = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.WhiteRGB, 6, "Tahoma", "Bold");
      //Create a call out
      var shieldCalloutSymbol = new CIMPointSymbolCallout();
      //Get a Shield symbolStyleItem from ArcGIS 2D StyleProjectitem
      var symbolStyleItem = GetPointSymbol("ArcGIS 2D", "Shield 1");
      //assign the point symbol (Highway shield) to the callout
      shieldCalloutSymbol.PointSymbol = symbolStyleItem.Symbol as CIMPointSymbol;
      shieldCalloutSymbol.PointSymbol.SetSize(18.0); //set symbol size
                                                     //Assign the callout to the text symbol
      textSymbolPointCallout.Callout = shieldCalloutSymbol;
      //Refer to the snippet "How to apply a Text Symbol to labels of a layer" below to see how to apply this text symbol to a label class
    
      //Gets a Highway point symbol from a style
      static SymbolStyleItem GetPointSymbol(string styleProjectItemName, string symbolStyleName)
      {
        var style2DProjectItem = Project.Current.GetItems<StyleProjectItem>().Where(p => p.Name == styleProjectItemName).FirstOrDefault();
        var symbolStyle = style2DProjectItem.SearchSymbols(StyleItemType.PointSymbol, symbolStyleName).FirstOrDefault();
        return symbolStyle;
      }
    }
    Snippet Creates a background callout text symbol
    /// <summary>
    /// Creates a solid fill background text symbol with an Accent bar and leader line.  The [CIMBackgroundCallout](https://pro.arcgis.com/en/pro-app/sdk/api-reference/#topic474.html) created has a solid fill aqua polygon, with a black dash-dot-dash leader line and a solid accent bar.
    /// ![lineCallOut](https://ArcGIS.github.io/arcgis-pro-sdk/images/Labeling//background-callout.png)
    /// </summary>
    {
      //Note: Run this code inside a QueuedTask
      var textSymbolBackgroundCallout = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 8, "Tahoma", "Bold");
      //Create a call out
      var backgroundCalloutSymbol = new CIMBackgroundCallout();
      //Leader line
      //Get a line symbol
      var lineSymbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 1, SimpleLineStyle.DashDotDot);
      //Create a solid fill polygon symbol for the callout.
      var aquaBackground = ColorFactory.Instance.CreateRGBColor(190, 255, 232, 100);
      var polySymbol = SymbolFactory.Instance.ConstructPolygonSymbol(aquaBackground, SimpleFillStyle.Solid);
      //assign the line to the callout
      backgroundCalloutSymbol.LeaderLineSymbol = lineSymbol;
      //Offset for the text
      textSymbolBackgroundCallout.OffsetX = 10;
      textSymbolBackgroundCallout.OffsetY = 10;
      //Assign the polygon to the background callout
      backgroundCalloutSymbol.BackgroundSymbol = polySymbol;
      //Accent bar
      var accentSymbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 2, SimpleLineStyle.Solid);
      backgroundCalloutSymbol.AccentBarSymbol = accentSymbol;
      //Set margins for the callout
      backgroundCalloutSymbol.Margin = new CIMTextMargin
      {
        Left = 5,
        Right = 5,
        Top = 5,
        Bottom = 5
      };
    
      //assign the callout to the textSymbol
      textSymbolBackgroundCallout.Callout = backgroundCalloutSymbol;
      //Refer to the snippet "How to apply a Text Symbol to labels of a layer" below to see how to apply this text symbol to a label class
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also