Я делаю игру с перетаскиванием для своего курса по вычислительной технике уровня A. Мое перетаскивание работает нормально, но у меня есть 6 кнопок / опций, и я хочу сбросить расположение других 5 кнопок, когда я нажимаю кнопку 1. Эти 6 кнопок называются btnAnswer1, btnAnswer2, btnAnswer3 и т. Д.
Я уже пытался найти решение, но оно все еще не работает
bool isDragged = false;
Point ptOffset;
private void buttonMouseDown(object sender, MouseEventArgs e) {
Button theButton = (Button)sender;
if (e.Button == MouseButtons.Left) {
isDragged = true;
Point ptStartPosition = theButton.PointToScreen(new Point(e.X, e.Y));
ptOffset = new Point();
ptOffset.X = theButton.Location.X - ptStartPosition.X;
ptOffset.Y = theButton.Location.Y - ptStartPosition.Y;
} else {
isDragged = false;
}
}
private void buttonMouseMove(object sender, MouseEventArgs e) {
Button theButton = (Button)sender;
if (isDragged) {
Point newPoint = theButton.PointToScreen(new Point(e.X, e.Y));
newPoint.Offset(ptOffset);
theButton.Location = newPoint;
}
}
private void buttonMouseUp(object sender, MouseEventArgs e) {
Button theButton = (Button)sender;
isDragged = false;
if ((theButton.Location.X >= 190 && theButton.Location.X <= 468) && (theButton.Location.Y >= 42 && theButton.Location.Y <= 236)) {
answerText = theButton.Text;
if (answerText == RandomQuestion[0].CorrectAnswerPosition) {
MessageBox.Show("Correct Answer");
}
else MessageBox.Show("Wrong Answer");
// disableDragDrop();
}
}
Я не знаю, как сбросить расположение других 5 кнопок, когда я перемещаю 1 кнопку.