如何在窗体使用各功能键作为快捷键?

来源:互联网 发布:linux p2p库 编辑:程序博客网 时间:2024/05/22 07:08

 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if ((e.KeyCode == Keys.F) && (e.Alt == true))
            {
                MessageBox.Show("ALT+F");
            } 

            if (e.KeyData == Keys.Insert)
            {
                Form2 f2 = new Form2();
                f2.Show();

            }  

              if(e.KeyCode.ToString()   ==   "F11")  
             {
                MessageBox.Show("I press the key of F11");

            }  

        }
    }

此外,还可以通过面板属性shortcut进行设置.

原创粉丝点击