Common Custom renderers
Common_CustomRenderers_CSharp\App_Code\LineColorRenderer.cs
// Copyright 2011 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See the use restrictions.
// 

namespace ESRI.ADF.Samples.Renderers
{
    /// <summary>
    /// Renders linear graphic features with color and thickness determined by designated attributes
    /// </summary>
    [System.Serializable]
    public class LineColorRenderer : ESRI.ADF.Samples.Renderers.RendererBase
    {
        #region Public Properties

        private string lineColorColumn = "Color";

        /// <summary>
        /// Name of the column that will determine a feature's color
        /// </summary>
        public string LineColorColumn
        {
            get { return lineColorColumn; }
            set { lineColorColumn = value; }
        }

        private string lineThicknessColumn = "Width";

        /// <summary>
        /// Name of the column that will determine the feature's line thickness
        /// </summary>
        public string LineThicknessColumn
        {
            get { return lineThicknessColumn; }
            set { lineThicknessColumn = value; }
        }

        #endregion

        #region IRenderer Members

        /// <summary>
        /// Main part of the IRenderer interface, within which a feature encapsulating the specified DataRow is to be 
        /// rendered on the specified graphics surface. The geometry instance has already been transformed to screen 
        /// coordinate, so we don't have to worry about that here.
        /// </summary>
        /// <param name="row">row containing the feature's data</param>
        /// <param name="graphics">GDI+ surface on which to render the feature</param>
        /// <param name="geometryColumn">column containing the feature's geometry</param>
        public override void Render(System.Data.DataRow row, System.Drawing.Graphics graphics, System.Data.DataColumn geometryColumn)
    {
            // Validate method input
      if (row == null || graphics == null || geometryColumn == null)
        return;

            // Validate input geometry
      ESRI.ArcGIS.ADF.Web.Geometry.Geometry adfGeometry = row[geometryColumn] as 
                ESRI.ArcGIS.ADF.Web.Geometry.Geometry;
      if (adfGeometry == null)
        return;

            // Initialize line color and thickness
      System.Drawing.Color lineColor = System.Drawing.Color.Black;
      float lineWidth = 1;

            // Get the feature's line thickness and color as specified by its attributes
      if (row.Table.Columns.Contains(this.LineThicknessColumn)) 
      {
        float.TryParse(row[this.LineThicknessColumn].ToString(), out lineWidth);
      }

      if (row.Table.Columns.Contains(this.LineColorColumn) && 
                row[this.LineColorColumn] is System.Drawing.Color) 
      {
        lineColor = (System.Drawing.Color)row[LineColorColumn];
      }

            // Draw the feature
            if (adfGeometry is ESRI.ArcGIS.ADF.Web.Geometry.Polygon)
            {
                Utility.DrawPolygon(graphics, adfGeometry as ESRI.ArcGIS.ADF.Web.Geometry.Polygon, lineColor, lineWidth);
            }
            else if (adfGeometry is ESRI.ArcGIS.ADF.Web.Geometry.Polyline)
            {
                Utility.DrawPolyline(graphics, adfGeometry as ESRI.ArcGIS.ADF.Web.Geometry.Polyline, lineColor, lineWidth);
            }
        }

        #endregion
    }
}