c# winform快捷键设置

设置 Form 的 KeyPreview=true 然后在Form 的案件事件里判断按钮类型进行分别调用就可以了

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (!ListViewModel)
            {

                if (e.Control)
                {
                    switch (e.KeyCode)
                    {
                        case Keys.A:
                            addTSB.PerformClick();
                            break;
                        case Keys.S:
                            saveTSB.PerformClick();
                            break;
                        case Keys.D:
                            delTSB.PerformClick();
                            break;
                        case Keys.R:
                            redoTSB.PerformClick();
                            break;
                        case Keys.P:
                            createDocTSB.PerformClick();
                            break;
                        case Keys.F:
                            findTSB.PerformClick();
                            break;
                        default:
                            break;
                    }
                    e.Handled = true;

                }
            }


        }

posted on 2013-10-15 11:04  NLazyo  阅读(484)  评论(0编辑  收藏  举报