this.KeyPreview = true;



private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {

            if (e.KeyCode == Keys.F1)
            {
                // Display a pop-up Help topic to assist the user.
                MessageBox.Show("你好");
            }
            else if (e.KeyCode == Keys.F2)
            {
                MessageBox.Show("好");
            }
        }

哪位看看,代码有错误吗?为什么我按F1和F2没反应呢?求解

 

        private void Form1_KeyDown(object sender, KeyEventArgs e)        

   {             switch (e.KeyCode)            

    {

                case Keys.F1:                    

        break;                

     case Keys.F2:                    

        break;                

     case Keys.F3:                    

         break;                    

      }            

     MessageBox.Show("key down is " + e.KeyCode.ToString());        

}  

我刚是了下,我这边成功了。语句和你写的一样,只是KeyPreview这个键值我是在form1的属性中设定的。

相关文章:

  • 2021-05-17
  • 2021-11-27
  • 2022-12-23
  • 2021-09-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案