title: Drawing an Image on Top on an Image in PictureBox by Capturing MouseUp and MouseMove(Drag and Draw Image)
body: <p>I'm trying to implement a image editor,i want to draw an image on top of existing  image on a picture box.I have achieved it using Graphics.DrawImage and using the MouseEventArguments point.But the problem is i want a selection rectangle drawn on top of the image being drawn when the mouse is clicked over it and it should be redrawn at a new position obtained by on click  and drag by the mouse(without selection rectangle).The rending of the image at the new position is slow and lots of memory is consumed so i use GC.collect.Please help me to implement the selection.I'm posting what i have done till now below</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  using System.Drawing.Drawing2D;
  
  namespace WindowsFormsApplication32
  {
      public partial class Form1 : Form
      {
          Bitmap timg, timg2;
          public Form1()
          {
              InitializeComponent();
          }
  
          private void Form1_Load(object sender, EventArgs e)
          {
              timg = new Bitmap(pictureBox1.Image);
              timg2 = new Bitmap(pictureBox1.Image);
             pictureBox1.MouseDown+=new MouseEventHandler(pictureBox1_MouseDown);
           pictureBox1.MouseMove+=new MouseEventHandler(pictureBox1_MouseMove);
  
          }
          private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
          {
              if (e.Button ==MouseButtons.Left)
              {
                  timg = new Bitmap(timg2);
  
                  Graphics g = Graphics.FromImage(timg);
                  g.DrawImage(pictureBox2.Image, new Point(e.X, e.Y));
                  pictureBox1.Image = timg;
                  g.Dispose();
                  GC.Collect();
                  //pictureBox1.Invalidate();
  
              }
          }
          private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
          {
              if (e.Button == MouseButtons.Left)
              {
                  Graphics g = Graphics.FromImage(pictureBox1.Image);
                  g.DrawImage(pictureBox2.Image, new Point(e.X, e.Y));
                 // pictureBox1.Invalidate();
                    g.Dispose();
                    GC.Collect();
              }
          }
  
          private void pictureBox1_Click(object sender, EventArgs e)
          {
  
          }
  
      }
  }
  </code></pre>