C# trying to capture the KeyDown event on a form

后端 未结 4 1029
不知归路
不知归路 2020-12-03 07:25

I am creating a small game, the game is printed onto a panel on a windows form. Now i want to capture the keydown event to see if its the arrow keys that has been pressed, t

4条回答
  •  不思量自难忘°
    2020-12-03 07:55

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            KeyPreview = true;
            KeyDown += new KeyEventHandler(Form1_KeyDown);
        }
    
        void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            System.Diagnostics.Debug.Write(e.KeyCode);
        }
    }
    

提交回复
热议问题