我之前詢問過這個問題的確曾搜索過谷歌。基本上我嘗試了一個小蛇遊戲。我的遊戲開始按箭頭鍵。焦點窗口形成時,此箭頭鍵處理。如果我們刪除每一種類型的按鈕和控件,然後把焦點放在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);
}
你可以嘗試男人嗎? –
看看窗體KeyPreview,並停止擔心焦點 –
我嘗試改變真實但問題相同.... –