winform中窗体的快捷鍵设置

1、将Form的KeyPreview属性设置True

2、对KeyDown事件写入代码
 private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F2)
            {
                MessageBox.Show("你按下了F2键");
                //解发button1的单击事件
                button1_Click(bt_save, null);
            }

        }

你可能感兴趣的:(WinForm)