Hope this code may hep you.
private Boolean dragInProgress = false;
private Control currentCtrl;
private int MouseDownX = 0;
private int MouseDownY = 0;
public MyFormSetting()
{
InitializeComponent();
MouseMoveEventRegister(new Control[] {labelPayeeName, labelDate, labelAmountInWords, labelAmount });
}
private void MouseMoveEventRegister(Control[] ctrlList)
{
foreach (Control ctrl in ctrlList)
{
ctrl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.labelMouseDownHandler);
ctrl.MouseMove += new System.Windows.Forms.MouseEventHandler(this.labelMouseMoveHandler);
ctrl.MouseUp += new System.Windows.Forms.MouseEventHandler(this.labelMouseUpHandler);
}
}
private void labelMouseDownHandler(object sender, MouseEventArgs e)
{
if (!dragInProgress)
{
dragInProgress = true;
MouseDownX = e.X;
MouseDownY = e.Y;
currentCtrl = (Control)sender;
}
}
private void labelMouseUpHandler(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
this.dragInProgress = false;
currentCtrl = null;
}
}
private void labelMouseMoveHandler(object sender, MouseEventArgs e)
{
if (dragInProgress)
{
Point temp = new Point();
temp.X = this.currentCtrl.Location.X + (e.X - MouseDownX);
temp.Y = this.currentCtrl.Location.Y + (e.Y - MouseDownY);
this.currentCtrl.Location = temp;
}
}