title: Compare two images with PictureBox controls
body: <p>I'm trying to achieve an effect similar to <a href="http://sfx.thelazy.net/games/screenshot/17321/full/" rel="nofollow">this site</a>. I am basically trying to implement a way to "compare" two similar images (with different colors, etc). I managed to do this in a not so brilliant way using two PictureBox controls (Winforms) one next to the other, and changing their Size and Location attributes on a MouseMove event.</p>
  
  <p>The result works, but it flickers a lot and it's not really the best way to do it.
  Is there a better way to do this, maybe with a WPF or by changing the code in any way? Here it is:</p>
  
  <pre><code>private void pbImg1_MouseMove(object sender, MouseEventArgs e)
      {
          pbImg2.Image = CropImage(array[1], new Rectangle(pbImg1.Size.Width, 0, totalSize.Width - pbImg1.Size.Width, 240));
          pbImg1.Size = new Size(e.X, pbImg1.Height);
          pbImg2.Location = new Point(pbImg1.Size.Width + pbImg1.Location.X, pbImg2.Location.Y);
          pbImg2.Size = new Size(totalSize.Width - pbImg1.Size.Width, 240);
  
          lpbImg1Size.Text = pbImg1.Size.ToString();
          lpbImg2Size.Text = pbImg2.Size.ToString();
          lpbImg1Location.Text = pbImg1.Location.ToString();
          lpbImg2Location.Text = pbImg2.Location.ToString();
      }
  
  private void pbImg2_MouseMove(object sender, MouseEventArgs e)
      {
          pbImg1.Image = CropImage(array[0], new Rectangle(0, 0, totalSize.Width - pbImg2.Size.Width, 240));
          pbImg1.Size = new Size(pbImg1.Width + e.X, 240);
  
          lpbImg1Size.Text = pbImg1.Size.ToString();
          lpbImg2Size.Text = pbImg2.Size.ToString();
          lpbImg1Location.Text = pbImg1.Location.ToString();
          lpbImg2Location.Text = pbImg2.Location.ToString();
      }
  
  public Bitmap CropImage(Bitmap source, Rectangle section)
      {
          // An empty bitmap which will hold the cropped image
  
          //TRY CATCH
          Bitmap bmp = new Bitmap(section.Width, section.Height);
  
          Graphics g = Graphics.FromImage(bmp);
  
          // Draw the given area (section) of the source image
          // at location 0,0 on the empty bitmap (bmp)
          g.DrawImage(source, 0, 0, section, GraphicsUnit.Pixel);
  
          return bmp;
      }
  </code></pre>
  
  <p>And here you can see the behavior of the program:
  <a href="https://gfycat.com/VillainousReadyAmazonparrot" rel="nofollow">https://gfycat.com/VillainousReadyAmazonparrot</a></p>