![](/img/trans.png)
[英]How would I use multiple radio buttons and multiple groups in one form so that only 1 button per row and column can be selected?
[英]How to reset the location of multiple buttons in a form when one button is moved
我正在为我的 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 个按钮的位置。
您可以通过这种方式更改按钮关闭位置
yourButton.Location = new Point(50, 50); //x and y cordinate off position
您应该在使用我的方法移动 1 个按钮的方法中放置 5 个按钮位置。 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.