title: Drag and drop in winforms
body: <p>I need to drag 6 images, which are in PictureBoxes, to 6 answer panels, one at a time and if the correct image is dragged to the correct spot it adds 1 to the score which is in a class called 'score'. There is code below to show one of the pcitures working but the form lags alot and if the image is dragged anywhere above the panel, it will snap into place. is there a way to stop this?</p>
  
  <pre><code>namespace DragAndDropQuiz
  </code></pre>
  
  <p>{
      public partial class Form2 : Form
      {
          public Form2()
          {
              InitializeComponent();</p>
  
  <pre><code>    }
  
      private void pcBxLiverpool_MouseEnter(object sender, EventArgs e)
      {
          this.Cursor = Cursors.Hand;
      }
  
      private void pcBxLiverpool_MouseLeave(object sender, EventArgs e)
      {
          this.Cursor = Cursors.Default;
      }
  
      private int xPos;
      private int yPos;
  
      private void pcBxGeneral_MouseDown(object sender, MouseEventArgs e)
      {
          if (e.Button == System.Windows.Forms.MouseButtons.Left)
          {
              xPos = e.X;
              yPos = e.Y;
          }
      }
  
      private void pcBxGeneral_MouseMove(object sender, MouseEventArgs e)
      {
          if (sender != null &amp;&amp; sender.GetType() == typeof(PictureBox))
          {
              if (e.Button == System.Windows.Forms.MouseButtons.Left)
              {
                  ((PictureBox)sender).Top += (e.Y - yPos);
                  ((PictureBox)sender).Left += (e.X - xPos);
                  this.Refresh();
              }
          }
      }
  
      private void pcBxGeneral_MouseUp(object sender, MouseEventArgs e)
      {
          if (sender != null &amp;&amp; sender.GetType() == typeof(PictureBox))
          {
              if (e.Button == System.Windows.Forms.MouseButtons.Left)
              {
                  PictureBox answer = (PictureBox)sender;
  
                  if (answer.Location.X &lt; pnlAnswer.Location.X)
                  {
                      if (answer.Location.X + answer.Width &gt; pnlAnswer.Location.X)
                      {
                          if ((answer.Location.X + answer.Width) &lt; pnlAnswer.Location.X + pnlAnswer.Width)
                          {
                              answer.Location = pnlAnswer.Location;
                          }
                      }
                  }
                  else if (answer.Location.X &gt; pnlAnswer.Location.X)
                  {
                      if (answer.Location.X &lt; (pnlAnswer.Location.X + pnlAnswer.Width))
                      {
                          answer.Location = pnlAnswer.Location;
                      }
                  }
              }
          }
      }
  
      private void Form2_Paint(object sender, PaintEventArgs e)
      {
  
      }
  
  
      private void groupBox2_Paint(object sender, PaintEventArgs e)
      {
         Graphics g = e.Graphics;
         g.DrawRectangle(new Pen(Color.Red), pnlAnswer.Location.X, pnlAnswer.Location.Y, pnlAnswer.Width, pnlAnswer.Height);
      }
  
  
  
  
  
  }
  </code></pre>
  
  <p>}</p>