下面是根据网上的相关资料修改的用鼠标拖动控件的例子: /// <summary> /// 用鼠标拖动Panel /// </summary> public class MovePanel : Panel { private bool whetherSelected = false; private Point p = new Point(); public bool WhetherSelected { get { return whetherSelected; } } /// <summary> /// 重写,设置绘制 /// </summary> protected override void OnCreateControl() { base.OnCreateControl(); SetStyle(ControlStyles.SupportsTransparentBackColor, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.DoubleBuffer, true); } /// <summary> /// OnMouseDown /// </summary> /// <param name="e"></param> protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); whetherSelected = true; p.X = Cursor.Position.X; p.Y = Cursor.Position.Y; } /// <summary> /// OnMouseMove /// </summary> /// <param name="e"></param> protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (whetherSelected == true) { if (this.IsParentMove) { this.Parent.Left = this.Parent.Left + (Cursor.Position.X - p.X); this.Parent.Top = this.Parent.Top + (Cursor.Position.Y - p.Y); } else { this.Left = this.Left + (Cursor.Position.X - p.X); this.Top = this.Top + (Cursor.Position.Y - p.Y); } p.X = Cursor.Position.X; p.Y = Cursor.Position.Y; } } /// <summary> /// OnMouseUp /// </summary> /// <param name="e"></param> protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); whetherSelected = false; this.BringToFront(); } private bool _IsParentMove = false; /// <summary> /// 是否移动父控件 /// </summary> public bool IsParentMove { get { return _IsParentMove; } set { _IsParentMove = value; } } }