我一直在尝试根据用户在Form1 KeyDown方法下按下各种箭头键在C#move中创建一个按钮,但我无法弄清楚如何使e的值等于用户输入。 到目前为止我有:
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Left)
{
button1.Location = new Point(button1.Top, button1.Left + 1);
}
else if (e.KeyCode == Keys.Right)
{
button1.Location = new Point(button1.Top, button1.Right + 1);
}
else if (e.KeyCode == Keys.Up)
{
button1.Location = new Point(button1.Top +1, button1.Right);
}
else if (e.KeyCode == Keys.Down)
{
button1.Location = new Point(button1.Top-1, button1.Right);
}
}
然后调用它我用
Form1_KeyDown(sender: Keys.A ,e: KeyDown);
但我不知道要为发件人或e的价值投入什么。如果有帮助,我的目标是让用户以一定的速度在屏幕周围操作一个按钮。谢谢!