【发布时间】:2013-11-27 19:22:53
【问题描述】:
我想知道如何通过触摸键盘上的箭头键来使按钮向上、向下、向右或向左移动。我试过了:
button1.Location.X += 1;
但是,我收到一条错误消息,说明它不是变量。所以,我也试过了:
public int xPos, yPos;
然后,在form1_keydown下面一点:
xPos = Convert.ToInt32(button1.Location.X);
yPos = Convert.ToInt32(button1.Location.Y);
if (e.KeyData == Keys.Up)
{
xPos += 1;
}
但是,它只是不起作用。请帮忙。谢谢!
【问题讨论】:
-
你试过
button1.Location = new Point(button1.Left + 1, button1.Top);吗? -
没关系,确实如此。谢谢!