This document is archived and information here might be outdated.  Recommended version.


Create Character Marker Symbol Snippet (ArcObjects .NET 10.4 SDK)
ArcObjects Library Reference

Create Character Marker Symbol Snippet

Create a default Character Marker Symbol by supplying a default symbol color, font size and character.

[C#]
///<summary>Create a default Character Marker Symbol by supplying a default symbol color, font size and character.</summary>
///  
///<param name="rgbColor">An IRgbColor interface that is the symbol color of the Character Marker Symbol.</param>
///<param name="fontSize">A System.Decimal that is the size of the font for the Character Marker Symbol. Example: 24.0</param>
///<param name="characterIndex">A System.Int32 that is the character index number of the font you want to create. Example: 36</param>
///   
///<returns>An ICharacterMarkerSymbol interface.</returns>
///   
///<remarks>
///   To find what character index you need for a particular font:
///   1. Open ArcMap
///   2. Add in any point dataset
///   3. Double click on a point symbol in the TOC
///   4. In the Symbol Selector dialog, click the properties button
///   5. In the Symbol Property Editor dialog, change the Type to 'Character Marker Symbol'
///   6. Choose the desired Font 
///   7. Click on the different character symbols to see what Unicode index numer you need
/// </remarks>
public ESRI.ArcGIS.Display.ICharacterMarkerSymbol CreateCharacterMarkerSymbol(ESRI.ArcGIS.Display.IRgbColor rgbColor, System.Double fontSize, System.Int32 characterIndex)
{

  if (rgbColor == null)
  {
    return null;
  }
  // Define the Font we want to use
  stdole.IFontDisp stdFont=new stdole.StdFontClass() as stdole.IFontDisp; // Dynamic Cast
  stdFont.Name="ESRI Default Marker";
  stdFont.Size=(System.Decimal)fontSize; // Explicit Cast

  // Set the CharacterMarkerSymbols Properties
  ESRI.ArcGIS.Display.ICharacterMarkerSymbol characterMarkerSymbol=new ESRI.ArcGIS.Display.CharacterMarkerSymbolClass();
  characterMarkerSymbol.Angle=0;  // 0 to 360
  characterMarkerSymbol.CharacterIndex=characterIndex;
  characterMarkerSymbol.Color=rgbColor;
  characterMarkerSymbol.Font=stdFont;
  characterMarkerSymbol.Size=fontSize;
  characterMarkerSymbol.XOffset=0;
  characterMarkerSymbol.YOffset=0;

  return characterMarkerSymbol;
}
[Visual Basic .NET]
'''<summary>Create a default Character Marker Symbol by supplying a default symbol color, font size and character.</summary>
'''  
'''<param name="rgbColor">An IRgbColor interface that is the symbol color of the Character Marker Symbol.</param>
'''<param name="fontSize">A System.Decimal that is the size of the font for the Character Marker Symbol. Example: 24.0</param>
'''<param name="characterIndex">A System.Int32 that is the character index number of the font you want to create. Example: 36</param>
'''   
'''<returns>An ICharacterMarkerSymbol interface.</returns>
'''   
'''<remarks>
'''   To find what character index you need for a particular font:
'''   1. Open ArcMap
'''   2. Add in any point dataset
'''   3. Double click on a point symbol in the TOC
'''   4. In the Symbol Selector dialog, click the properties button
'''   5. In the Symbol Property Editor dialog, change the Type to 'Character Marker Symbol'
'''   6. Choose the desired Font 
'''   7. Click on the different character symbols to see what Unicode index numer you need
''' </remarks>
Public Function CreateCharacterMarkerSymbol(ByVal rgbColor As ESRI.ArcGIS.Display.IRgbColor, ByVal fontSize As System.Double, ByVal characterIndex As System.Int32) As ESRI.ArcGIS.Display.ICharacterMarkerSymbol

  If rgbColor Is Nothing Then

        Return Nothing

  End If

  ' Define the Font we want to use
  Dim stdFont As stdole.IFontDisp=CType(New stdole.StdFont, stdole.IFontDisp) ' Explicit Cast
  stdFont.Name="ESRI Default Marker"
  stdFont.Size=CDec(fontSize)

  ' Set the CharacterMarkerSymbols Properties
  Dim characterMarkerSymbol As ESRI.ArcGIS.Display.ICharacterMarkerSymbol=New ESRI.ArcGIS.Display.CharacterMarkerSymbolClass

  With characterMarkerSymbol

    .Angle=0 ' 0 to 360
    .CharacterIndex=characterIndex
    .Color=rgbColor
    .Font=stdFont
    .Size=fontSize
    .XOffset=0
    .YOffset=0

  End With

  Return characterMarkerSymbol

End Function

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.Display
  • ESRI.ArcGIS.System
  • stdole