title: Fast way to draw lines using different Color using GDI+?
body: <p>I have an dynamic List of Point, new Point can be added at any time. I want to draw lines to connect them using different color. Color is based on the index of those points. Here is the code:</p>
  
  <pre><code>    private List&lt;Point&gt; _points;
      private static Pen pen1 = new Pen(Color.Red, 10);
      private static Pen pen2 = new Pen(Color.Yellow, 10);
      private static Pen pen3 = new Pen(Color.Blue, 10);
      private static Pen pen4 = new Pen(Color.Green, 10);
  
      private void Init()
      {
          // use fixed 80 for simpicity
          _points = new List&lt;Point&gt;(80);
  
          for (int i = 0; i &lt; 80; i++)
          {
              _points.Add(new Point(30 + i * 10, 30));
          }
      }
  
      private void DrawLinesNormal(PaintEventArgs e)
      {
          for (int i = 0; i &lt; _points.Count-1; i++)
          {
              if (i &lt; 20)
                  e.Graphics.DrawLine(pen1, _points[i], _points[i + 1]);
              else if (i &lt; 40)
                  e.Graphics.DrawLine(pen2, _points[i], _points[i + 1]);
              else if (i &lt; 60)
                  e.Graphics.DrawLine(pen3, _points[i], _points[i + 1]);
              else
                  e.Graphics.DrawLine(pen4, _points[i], _points[i + 1]);
          }
      }
  </code></pre>
  
  <p>I find this method is not fast enough when I have new points coming in at a high speed. Is there any way to make it faster? I did some research and someone said using GraphicsPath could be faster, but how?</p>
  
  <p>[UPDATE] I collect some possible optimizations:  </p>
  
  <ol>
  <li>Using GrahpicsPath, <a href="https://stackoverflow.com/questions/1074813/looking-for-a-faster-than-gdi-solution-for-rendering-dynamic-data-plots/1243503#1243503">Original Question</a></li>
  <li>Change Graphics quality ( such as SmoothingMode/PixelOffsetMode...), also call SetClip to specify the only necessary region to render.</li>
  </ol>