ArcObjects Library Reference

Create Gradient Fill Symbol Snippet

Create Gradient Fill Symbol by specifying the starting and ending colors and the number of levels to make in between.

[C#]

///<summary>Create Gradient Fill Symbol by specifying the starting and ending colors and the number of levels to make in between.</summary>
///  
///<param name="startRgbColor">An IRgbColor interface that is the beginning color for the ramp.</param>
///<param name="endRgbColor">An IRgbColor interface that is the ending color for the ramp.</param>
///<param name="numberOfIntervals">A System.Int32 that is the number of color level gradiations that the color ramp will make.</param>
///   
///<returns>An IGradientFillSymbol interface.</returns>
///   
///<remarks></remarks>
public ESRI.ArcGIS.Display.IGradientFillSymbol CreateGradientFillSymbol(ESRI.ArcGIS.Display.IRgbColor startRgbColor, ESRI.ArcGIS.Display.IRgbColor endRgbColor, System.Int32 numberOfIntervals)
{

  if (startRgbColor == null || endRgbColor == null || numberOfIntervals < 0)
  {
    return null;
  }
  // Create the Ramp for the Gradient Fill
  ESRI.ArcGIS.Display.IAlgorithmicColorRamp algorithmicColorRamp = new ESRI.ArcGIS.Display.AlgorithmicColorRampClass();
  algorithmicColorRamp.FromColor = startRgbColor;
  algorithmicColorRamp.ToColor = endRgbColor;
  algorithmicColorRamp.Algorithm = ESRI.ArcGIS.Display.esriColorRampAlgorithm.esriHSVAlgorithm;

  // Create the Gradient Fill
  ESRI.ArcGIS.Display.IGradientFillSymbol gradientFillSymbol = new ESRI.ArcGIS.Display.GradientFillSymbolClass();
  gradientFillSymbol.ColorRamp = algorithmicColorRamp;
  gradientFillSymbol.GradientAngle = 45;
  gradientFillSymbol.GradientPercentage = 0.9;
  gradientFillSymbol.IntervalCount = numberOfIntervals;
  gradientFillSymbol.Style = ESRI.ArcGIS.Display.esriGradientFillStyle.esriGFSLinear;

  return gradientFillSymbol;
}
[Visual Basic .NET]

'''<summary>Create Gradient Fill Symbol by specifying the starting and ending colors and the number of levels to make in between.</summary>
'''  
'''<param name="startRgbColor">An IRgbColor interface that is the beginning color for the ramp.</param>
'''<param name="endRgbColor">An IRgbColor interface that is the ending color for the ramp.</param>
'''<param name="numberOfIntervals">A System.Int32 that is the number of color level gradiations that the color ramp will make.</param>
'''   
'''<returns>An IGradientFillSymbol interface.</returns>
'''   
'''<remarks></remarks>
Public Function CreateGradientFillSymbol(ByVal startRgbColor As ESRI.ArcGIS.Display.IRgbColor, ByVal endRgbColor As ESRI.ArcGIS.Display.IRgbColor, ByVal numberOfIntervals As System.Int32) As ESRI.ArcGIS.Display.IGradientFillSymbol

  If startRgbColor Is Nothing OrElse endRgbColor Is Nothing OrElse numberOfIntervals < 0 Then
	  Return Nothing
  End If

  ' Create the Ramp for the Gradient Fill
  Dim algorithmicColorRamp As ESRI.ArcGIS.Display.IAlgorithmicColorRamp = New ESRI.ArcGIS.Display.AlgorithmicColorRampClass
  With algorithmicColorRamp
    .FromColor = startRgbColor
    .ToColor = endRgbColor
    .Algorithm = ESRI.ArcGIS.Display.esriColorRampAlgorithm.esriHSVAlgorithm
  End With

  ' Create the Gradient Fill
  Dim gradientFillSymbol As ESRI.ArcGIS.Display.IGradientFillSymbol = New ESRI.ArcGIS.Display.GradientFillSymbolClass
  With gradientFillSymbol
    .ColorRamp = algorithmicColorRamp
    .GradientAngle = 45
    .GradientPercentage = 0.9
    .IntervalCount = numberOfIntervals
    .Style = ESRI.ArcGIS.Display.esriGradientFillStyle.esriGFSLinear
  End With

  Return gradientFillSymbol

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