title: C# Drag & Drop labels
body: <p>i have a problem with drag&amp;drop. I have code:</p>
  
  <pre><code>      void labelWorker_MouseEvent(object sender, MouseEventArgs e)
      {
          Label labelWorker = (Label)sender;
          labelWorker.DoDragDrop(labelWorker, DragDropEffects.Move);
          labelWorker.MouseDown += new MouseEventHandler(labelWorker_MouseDown);
          labelWorker.MouseMove += new MouseEventHandler(labelWorker_MouseMove);
          labelWorker.MouseUp += new MouseEventHandler(labelWorker_MouseUp);
      }
  
          bool isDragged = false;
          Point ptOffset;
      void labelWorker_MouseDown(object sender, MouseEventArgs e)
      {
          if (e.Button == MouseButtons.Left)
          {
              Label labelWorker = (Label)sender;
              isDragged = true;
              Point ptStartPosition = labelWorker.PointToScreen(new Point(e.X, e.Y));
  
              ptOffset = new Point();
              ptOffset.X = labelWorker.Location.X - ptStartPosition.X;
              ptOffset.Y = labelWorker.Location.Y - ptStartPosition.Y;
          }
          else
          {
              isDragged = false;
          }
      }
  
      void labelWorker_MouseMove(object sender, MouseEventArgs e)
      {
          Label labelWorker = (Label)sender;
          if (isDragged)
          {
              Point newPoint = labelWorker.PointToScreen(new Point(e.X, e.Y));
              newPoint.Offset(ptOffset);
              labelWorker.Location = newPoint;
          }
      }
  
      void labelWorker_MouseUp(object sender, MouseEventArgs e)
      {
          Label labelWorker = (Label)sender;
          isDragged = false;            
      }
  </code></pre>
  
  <p>Label starts freaking out when I try to move it. I think the problem is in</p>
  
  <pre><code>  void labelWorker_MouseMove(object sender, MouseEventArgs e)
     {
         Label labelWorker = (Label)sender;
         if (isDragged)
           {
             Point newPoint = labelWorker.PointToScreen(new Point(e.X, e.Y));
             newPoint.Offset(ptOffset);
             labelWorker.Location = newPoint;
           }
     }
  </code></pre>