I'm trying to move a button control at run time with the intent of having the control act exactly like moving a button control does in the designer. When I click on the control and attempt to drag it across the form it disappears and then pops up in a different place on the form from where it was dragged to. Can someone please tell me what is wrong with the code?
publicpartialclassForm1 : Form{
privatebool dragging = false;
public Form1()
{
InitializeComponent();
}
privatevoid button1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (dragging)
{
button1.Location = newPoint(e.X, e.Y);
}
}
privatevoid button1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (!dragging && e.Button == MouseButtons.Left)
{
dragging = true;
}
}
privatevoid button1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
dragging = false;
}
}