title: How to draw a Moving arrow image in C#
body: <p>I have to draw a moving Arrow image (using C# code VS2008) between 2 Bars (image). I tried it with two approaches:</p>
  
  <ol>
  <li>Draw arrow figure by joining points. and then keep changing the x,y coordinates.</li>
  <li>making an arrow image and then keep changing its position.</li>
  </ol>
  
  <p>The issue is flickering. Whenever I move the arrow image (or redraw the points) nearby images (actually there few other images as Bars are there) flickers. I tried to call invalidate(rect) thinking it will redraw the given rectangle only but still as soon the arrow image crosses these bars, everything flickers. which doesn't look good. how can I move this arrow image in a smooth fashion. Pls. suggest. Or should I adopt another approach?  </p>
  
  <p>// Code: **</p>
  
  <p>public partial class Form1 : Form
  {
      private Bitmap bitmapAntenna;
      private Bitmap bitmapArrow;</p>
  
  <pre><code>public Form1()
  {
      bitmapAntenna = new Bitmap("D:\\AntennaBar.JPG");
      bitmapArrow = new Bitmap("D:\\Arrow.JPG");
  }
  
  private void DrawAntennaImages(int antennaNo)
  {
      Graphics grph = this.CreateGraphics();
      if (1 == antennaNo)
      {
          grph.DrawImage(bitmapAntenna, new RectangleF(350, 300, bitmapAntenna.Width*(1.00F), bitmapAntenna.Height*(1.00F))) ;
      }
      else
          grph.DrawImage(AntennaImage, new Point(550, 300));
  }
  
  private void DrawArrowImages(int X)
  {
      Graphics grph = this.CreateGraphics();
      grph.DrawImage(bitmapArrow, new Point(380 + X, 350));
  }
  
  private void PaintHandler(Object sender, System.Windows.Forms.PaintEventArgs e)
  {
      DrawAntennaImages(1);
      DrawAntennaImages(2);
  }
  
  private void button_Click(object sender, EventArgs e)
  {
      for (int i = 1; i &lt; 40; i++)
      {
          //  Note: first draw antenna 1 image, arrow image then antenna 2 image so that arrow will overlap
          //  only antenna 1 image only.
  
          DrawAntennaImages(1);       //  Draw Antenn 1 image
          DrawArrowImages(i * 2);     //  Draw Arrow image
          DrawAntennaImages(2);       //  Draw Antenn 2 image
  
          System.Threading.Thread.Sleep(25);  //  Sleep before drawing next time ..
      }
      this.Invalidate(); // If I don't call this, arrow image does not elope after last draw
  }
  </code></pre>
  
  <p>}</p>
  
  <p>// In designer </p>
  
  <p>this.Paint += new System.Windows.Forms.PaintEventHandler(this.PaintHandler);</p>
  
  <p>//Code <em>*</em></p>
  
  <p>Thanks
  RPS</p>