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; namespace WindowsFormsApplication1 { class DdBotton : Button { public DdBotton() { this.MouseDown += new MouseEventHandler(DdBotton_MouseDown); this.MouseUp += new MouseEventHandler(DdBotton_MouseUp); this.MouseMove += new MouseEventHandler(DdBotton_MouseMove); } Point MousePoint; void DdBotton_MouseMove(object sender, MouseEventArgs e) { if ((e.Button & MouseButtons.Left) == MouseButtons.Left) { if (this.MousePoint != Point.Empty) { this.Left += e.X - this.MousePoint.X; this.Top += e.Y - this.MousePoint.Y; } } } void DdBotton_MouseUp(object sender, MouseEventArgs e) { this.MousePoint = Point.Empty; } void DdBotton_MouseDown(object sender, MouseEventArgs e) { if((e.Button & MouseButtons.Left) == MouseButtons.Left) { if (this.MousePoint == Point.Empty) { this.MousePoint = new Point(e.X, e.Y); } } } } }