Hi MAY,
This is simple enough, you need to handle the buttons mousedown and mousemove events.
private int startX = 0; //
private int startY = 0; // these will know the start position of the drag procedure
private void button1_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Left) // store start position
{
startX = e.X;
startY = e.Y;
}
}
private void button1_MouseMove(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
// if Left button is down we have a drag
// set the buttons new position based on the difference
// between the current mouse position and the start position
button1.Location = new Point(button1.Left + (e.X-startX), button1.Top + (e.Y-startY));
}
}
Note, this code will let you drag the button outside the form, so you