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


Create Cartographic Line Symbol Snippet (ArcObjects .NET 10.5 SDK)
ArcObjects Library Reference

Create Cartographic Line Symbol Snippet

Create a default Cartographic Line Symbol by supplying a line color.

[C#]
///<summary>Create a default Cartographic Line Symbol by supplying a line color.</summary>
///  
///<param name="rgbColor">An IRgbColor interface that is colro for the Cartographic Line Symbol.</param>
///   
///<returns>An ICartographicLineSymbol interface.</returns>
///   
///<remarks></remarks>
public ESRI.ArcGIS.Display.ICartographicLineSymbol CreateCartographicLineSymbol(ESRI.ArcGIS.Display.IRgbColor rgbColor)
{
  if(rgbColor == null)
  {
    return null;
  }
  
  // Makes a new Cartographic Line symbol and sets its properties
  ESRI.ArcGIS.Display.ICartographicLineSymbol cartographicLineSymbol=new ESRI.ArcGIS.Display.CartographicLineSymbolClass();

  // In order to set additional properties like offsets and dash patterns we must create an ILineProperties object
  ESRI.ArcGIS.Display.ILineProperties lineProperties=cartographicLineSymbol as ESRI.ArcGIS.Display.ILineProperties;
  lineProperties.Offset=0;

  // Here's how to do a template for the pattern of marks and gaps
  System.Double[] hpe=new System.Double[6];
  hpe[0]=0;
  hpe[1]=7;
  hpe[2]=1;
  hpe[3]=1;
  hpe[4]=1;
  hpe[5]=0;

  ESRI.ArcGIS.Display.ITemplate template=new ESRI.ArcGIS.Display.TemplateClass();
  template.Interval=1;
  for (System.Int32 i=0; i < hpe.Length; i=i + 2)
  {
    template.AddPatternElement(hpe[i], hpe[i + 1]);
  }


  lineProperties.Template=template;

  // Set the basic and cartographic line properties
  cartographicLineSymbol.Width=2;
  cartographicLineSymbol.Cap=ESRI.ArcGIS.Display.esriLineCapStyle.esriLCSButt;
  cartographicLineSymbol.Join=ESRI.ArcGIS.Display.esriLineJoinStyle.esriLJSBevel;
  cartographicLineSymbol.Color=rgbColor;

  return cartographicLineSymbol;
}
[Visual Basic .NET]
'''<summary>Create a default Cartographic Line Symbol by supplying a line color.</summary>
'''  
'''<param name="rgbColor">An IRgbColor interface that is colro for the Cartographic Line Symbol.</param>
'''   
'''<returns>An ICartographicLineSymbol interface.</returns>
'''   
'''<remarks></remarks>
Public Function CreateCartographicLineSymbol(ByVal rgbColor As ESRI.ArcGIS.Display.IRgbColor) As ESRI.ArcGIS.Display.ICartographicLineSymbol

  If rgbColor Is Nothing Then

    Return Nothing

  End If

  ' Makes a new Cartographic Line symbol and sets its properties
  Dim cartographicLineSymbol As ESRI.ArcGIS.Display.ICartographicLineSymbol=New ESRI.ArcGIS.Display.CartographicLineSymbolClass

  ' In order to set additional properties like offsets and dash patterns we must create an ILineProperties object
  Dim lineProperties As ESRI.ArcGIS.Display.ILineProperties=TryCast(cartographicLineSymbol, ESRI.ArcGIS.Display.ILineProperties) ' Dynamic Cast
  lineProperties.Offset=0

  ' Here's how to do a template for the pattern of marks and gaps
  Dim hpe As System.Double()=New System.Double(5){}
  hpe(0)=0
  hpe(1)=7
  hpe(2)=1
  hpe(3)=1
  hpe(4)=1
  hpe(5)=0

  Dim template As ESRI.ArcGIS.Display.ITemplate=New ESRI.ArcGIS.Display.TemplateClass
  template.Interval=1

  Dim i As System.Int32=0

  Do While i < hpe.Length

          template.AddPatternElement(hpe(i), hpe(i + 1))
          i=i + 2

  Loop

  lineProperties.Template=template

  ' Set the basic and cartographic line properties
  cartographicLineSymbol.Width=2
  cartographicLineSymbol.Cap=ESRI.ArcGIS.Display.esriLineCapStyle.esriLCSButt
  cartographicLineSymbol.Join=ESRI.ArcGIS.Display.esriLineJoinStyle.esriLJSBevel
  cartographicLineSymbol.Color=rgbColor

  Return cartographicLineSymbol

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