title: Error when drawing line in Graphics.DrawLine C# Visual Studio
body: <pre><code>private void Form1_Paint(object sender, PaintEventArgs e)
      {
          Graphics l = e.Graphics;
          Pen p = new Pen(Color.Black, 1);
          float angle = 0;
          float len = 100;
          PointF ori = new PointF(Width/2, 0);    
          PointF bob = new PointF(Width/2, len);
          while(true)
          {
  
              bob.X = ori.X + len * (float)Math.Sin(angle);
              bob.Y = ori.Y + len * (float)Math.Cos(angle);
              angle += 0.001F;
              l.DrawLine(p, ori.X, ori.Y, bob.X, bob.Y);
              l.DrawEllipse(p, bob.X - 15, bob.Y, 30, 30);
              if(angle == 360)
              {
                  break;
              }
              l.Dispose();
          } 
      }
  </code></pre>
  
  <p>The error line is l.DrawLine(p, ori.X, ori.Y, bob.X, bob.Y).
  Error type: System.ArgumentException. Error Message: Parameter is not valid.</p>
  
  <p>At first I thought the issue was with the floats but the DrawLine allows for such datatypes. It loops through once the error seems to occur when angle>0. Its magnitude doesn't seem to be the issue. Any help would be much appreciated. Thanks in advance. [UPDATE] Error seems to be with the l.Dispose</p>