Your code is not working because you are confusing Form co-ordinate space with Button co-ordinate space.
You need to record the Point where the Mouse goes down on the Button: that Point will be in Button co-ordinate space: i.e., relative to the upper-left of the Button as 0,0. And, that Point is available in the MouseEventArgs instance passed into the Button MouseDown EventHandler, accessible through the variable name 'e.
When you move the Mouse, you need to calculate an offset between the Point where the Mouse is right now ... in the MouseMove EventHandler ... (once again available in the 'e variable), and the Point the Mouse first went down.
That offset, then, can be applied to re-locate the Button, and your current Mouse-Cursor position will be maintained.
Then that same offset can be used to relocate your RussianKeyboard control.
Try this:
private bool dragging = false;
private int mX;
private int mY;
private int dX;
private int dY;
private void ButtonMoveKeyBoard_MouseDown(object sender, MouseEventArgs e)
{
dragging = true;
mX = e.X;
mY = e.Y;
ButtonMoveKeyboard.BackColor = Color.LimeGreen;
}
private void ButtonMoveKeyBoard_MouseUp(object sender, MouseEventArgs e)
{
dragging = false;
ButtonMoveKeyboard.BackColor = Color.SandyBrown;
}
private void ButtonMoveKeyBoard_MouseMove(object sender, MouseEventArgs e)
{
if (dragging)
{
dX = e.X - mX;
dY = e.Y - mY;
ButtonMoveKeyboard.Left += dX;
ButtonMoveKeyboard.Top += dY;
russianKeyboard1.Left += dX;
russianKeyboard1.Top += dY;
}
}
}
In this example, I'm using variables dX, dY, to store the calculated offsets because: they are used twice.