private void Form1_Load(object sender, EventArgs e) { Form.CheckForIllegalCrossThreadCalls = false; Button2.Select(); //轉移焦點到Button2 P.Left = 180; Q.Left = 180; Panel1.Width = 410; }
private void Form1_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.Z: if (P.Left > 2) { P.Left -= 10; //左移 } break; case Keys.X: if (P.Left < 355) { P.Left += 10; //右移 } break; case Keys.Space: MyShot(); //開槍 player.SoundLocation = Application.StartupPath + @"\\shoot.wav"; player.Play(); break; } if (ListBox1.SelectedIndex >= 0)//有選取遊戲對手,上線遊戲中 { switch (e.KeyCode) { case Keys.Z: //移動飛機 Send("3" + P.Left.ToString() + "|" + ListBox1.SelectedItem); //傳送位置訊息 break; case Keys.X: //移動飛機 Send("3" + P.Left.ToString() + "|" + ListBox1.SelectedItem); //傳送位置訊息 break; case Keys.Space: //開槍 Send("4" + "S" + "|" + ListBox1.SelectedItem); //傳送開槍訊息 break; } Button2.Select(); //轉移焦點到Button2 } }
private void ListBox1_SelectedIndexChanged(object sender, EventArgs e) { Button2.Select(); }