title: How to synchronize picturebox images
body: <p>In my winforms application written in C#, I need to synchronize the timing of 2 GIF-images placed on 2 pictureboxes. That means, one picturebox has one animated GIF-image and the second picturebox has the same animated GIF-image, but with different colors. Both images have to be displayed in the same frame-sequence, when the second picturebox appears.</p>
  
  <p>Based on King King's answer in <a href="https://stackoverflow.com/questions/17008254/need-to-select-a-frame-in-gif">this thread</a>, I implemented this extension methods:</p>
  
  <pre><code>public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
      }
  
      private void _buttonTest_Click(object sender, EventArgs e)
      {
          _pictureBox2.Visible = !_pictureBox2.Visible;
  
          if (_pictureBox2.Visible)
              _pictureBox2.SynchronizeWith(_pictureBox1);
      }
  }
  
  public static class PictureBoxServices
  {
      public static void SetPictureFrameIndex(this PictureBox pictureBox, int index)
      {
          pictureBox.Image.SelectActiveFrame(new FrameDimension(pictureBox.Image.FrameDimensionsList[0]), index);
          pictureBox.Image = pictureBox.Image;    // restart on selected index
      }
  
      public static int GetPictureFrameIndex(this PictureBox pictureBox)
      {
          throw new NotImplementedException();
      }
  
      public static void SynchronizeWith(this PictureBox pictureBoxThis, PictureBox pictureBoxToSynchronizeWith)
      {
          pictureBoxThis.SetPictureFrameIndex(pictureBoxToSynchronizeWith.GetPictureFrameIndex());
      }
  }
  </code></pre>
  
  <p>I have 2 problems:</p>
  
  <ol>
  <li>I dont know how to implement GetPictureFrameIndex</li>
  <li>SetPictureFrameIndex is not working. It sets and displays the selected frame, but the next displayed frame is always with frameindex = 1, not frameindex = index + 1</li>
  </ol>
  
  <p>Can someone help me please?
  Even a hack-solution using reflection would be OK (if using reflection is needed).</p>