【发布时间】:2019-03-25 01:20:10
【问题描述】:
我正在为我的 A 级计算课程制作一个拖放游戏。我的拖放工作正常,但我有 6 个按钮/选项,当我移动 1 个按钮时,我想重置其他 5 个按钮的位置。这 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();
}
}
当我移动 1 个按钮时,我不知道如何重置其他 5 个按钮的位置。
【问题讨论】:
标签: c# drag-and-drop