title: Graphics DrawImage - ArgumentException: 'Parameter is not valid.'
body: <p>I have timer which adds new image on the panel every second. First i create my global variable Graphics g, create timer in the construcor and start timer there. In my Panel method i create Graphics object (g = e.Graphics) and then in my timer method i use that g object to draw new image. Can't find what's the problem, here's the core code (program stops when on the first call - g.DrawImage()):</p>
  
  <pre><code>public partial class MyClass: Form
  {
  private Timer addImage;
  
  private Image img;
  
  private Graphics g;
  private Point pos;
  
  public MyClass()
  {
      InitializeComponent();
  
      img = Image.FromFile("C:/image.png");
      pos = new Point(100, 100);
  
      addImage = new Timer()
      {
          Enabled = true,
          Interval = 3000,
      };
      addImage.Tick += new EventHandler(AddImage);
      addImage.Start();
  }
  
  private void MyPanel_Paint(object sender, PaintEventArgs e)
  {
      g = e.Graphics;
  }
  
  private void AddImage(Object myObject, EventArgs myEventArgs)
  {
      g.DrawImage(img, pos); // ArgumentException: 'Parameter is not valid.'
  
      MyPanel.Invalidate();
  }
  }
  </code></pre>