I need to drag controls (Label) on panel and when dragging I want to move the control. I did it this way:
private Point MouseDownLocation;
private void Form1_Load(object sender, EventArgs e)
{
}
private void label1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
MouseDownLocation = e.Location;
}
}
private void label1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
label1.Left = e.X + label1.Left - MouseDownLocation.X;
label1.Top = e.Y + label1.Top - MouseDownLocation.Y;
}
}
private void panel1_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
} I now need to have labels in the center of the container when I drop them. How to do it?