public partial class Form1 : Form
{
int _x, _y;
bool _moving;
public Form1()
{
_moving = false;
InitializeComponent();
}
private void label1_MouseDown(object sender, MouseEventArgs e)
{
_x = e.X;
_y = e.Y;
_moving = true;
}
private void label1_MouseMove(object sender, MouseEventArgs e)
{
if (_moving)
{
label1.Left += e.X - _x;
label1.Top += e.Y - _y;
}
}
private void label1_MouseUp(object sender, MouseEventArgs e)
{
if (_moving)
{
if (Rectangle.Intersect(new Rectangle(label1.Left, label1.Top, label1.Left + label1.Width, label1.Top + label1.Height), new Rectangle(panel1.Left, panel1.Top, panel1.Left + panel1.Width, panel1.Top + panel1.Height)) != null)
{
panel1.Controls.Add(label1);
}
_moving = false;
}
}
}