Search

Mouse Drag and Drop using C#

using System.Drawing;
using System.Windows.Forms;

namespace IndiLogix.MouseDrag
{
 static class mouseDrag
 {
  private static Point mouse_offset; // Mouse Point Strut

  // Mouse Down Mouse Offset
  public static void mOffset(MouseEventArgs e)
  {
   mouse_offset = new Point(-e.X, -e.Y);
  }

  // Mouse Down Mouse Move
  public static void mMove(MouseEventArgs e,Form frm)
  {
   if (e.Button == MouseButtons.Left)
   {
    Point mousePos = Control.MousePosition;
    mousePos.Offset(mouse_offset.X, mouse_offset.Y);
    //this.Location = mousePos;
    frm.Location = mousePos;
   }
  }

 }
}