我在问这个问题之前确实搜索过谷歌。基本上我已经尝试了一个小蛇游戏。我的游戏从向下箭头键开始。此箭头键在焦点窗口形成时起作用。如果我们删除每种类型的按钮和控件,然后将焦点放在 windows 窗体上,否则不会将焦点设置在 windows 窗体上。我刚刚在按钮上添加了按钮焦点设置。任何人的帮助,并提前感谢..
private void Key_down(object sender, KeyEventArgs e)
{
int xx = pictureBox1.Location.X;
int yy = pictureBox1.Location.Y;
i = xx;
ii = yy;
if (e.KeyCode == Keys.Right)
{
// x = x + 1;
// MessageBox.Show("Test");
// pictureBox1.DisplayRectangle = Rectangle.
cr = true;
cl = false;
cu = false;
cd = false;
// pictureBox1.Location = new Point(x, y);
}
else if (e.KeyCode == Keys.Left)
{
cl = true;
cr = false;
cu = false;
cd = false;
}
else if (e.KeyCode == Keys.Up)
{
cu = true;
cl = false;
cr = false;
cd = false;
}
else if (e.KeyCode == Keys.Down)
{
cd = true;
cu = false;
cr = false;
cl = false;
}
// pictureBox1.Location = new Point(x, y);
}