设置屏幕按钮的快捷键方法:

KeyPreview的属性设置为True

 //设置快捷键
        private void TestMain_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.Modifiers.CompareTo(Keys.Alt) ==0)
            {
                //选择导购员
                if(e.KeyCode == Keys.Q)
                {
                    ddlSaleMan.Focus();
                    ddlSaleMan.SelectedIndex = 0;
                }
                //客户编码
                if (e.KeyCode == Keys.W)
                {
                    txtCusCode.Focus();
                    txtCusCode.SelectAll();
                }
                //手动抹零
                if (e.KeyCode == Keys.E)
                {
                    txbManuallySetZero.Focus();
                    txbManuallySetZero.SelectAll();
                }
            }
            switch (e.KeyCode)
            {
                //结账
                case Keys.F1:
                    btnCheckout_Click(sender, e);
                    break;
                //取单
                case Keys.F2:
                    btnTakeMenu_Click(sender, e);
                    break;
                //存单
                case Keys.F3:
                    btnSaveMenu_Click(sender, e);
                    break;
                //改价
                case Keys.F4:
                    btnUpatePrice_Click(sender, e);
                    break;
                //改数
                case Keys.F5:
                    btnUpdateAmount_Click(sender, e);
                    break;
                //删除
                case Keys.F6:
                    btnDelMenu_Click(sender, e);
                    break;
                //赠单
                case Keys.F7:
                    btnFreeMenu_Click(sender, e);
                    break;
                //录入临时品项
                case Keys.F8:
                    btnImport_Click(sender, e);
                    break;
                //结账单补打
                case Keys.F9:
                    btnPrintAgain_Click(sender, e);
                    break;
                //清除
                case Keys.F10:
                    btnClearForm_Click(sender, e);
                    break;
                //
                case Keys.F11:
                    break;
                case Keys.PageDown: //付款
                    if (MessageBox.Show("确定选择付款方式吗?", "付款方式选择", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        gruopXF.Focus();
                        gruopXF.BackColor = Color.Khaki;
                    }
                    break;
                case Keys.Escape: //系统退出
                    if (MessageBox.Show("确实要退出吗?", "退出程序", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        UserService.ClearUserLock(UserCode);
                        Application.Exit();
                    }
                    break;

                default:
                    break;


            }

            //数据快捷键操作
            if (ActiveControl.GetType().Name != "GroupBox")
                return;
            #region 数据快捷键
            if (e.Modifiers != Keys.Alt)
            {
                return;
            }
            else
            {
                switch (e.KeyCode)
                {
                    case Keys.NumPad1:
                        cbCash.Checked = true;
                        txbCash.Focus();
                        break;
                    case Keys.D1:
                        cbCash.Checked = true;
                        txbCash.Focus();
                        break;

                    case Keys.NumPad2:
                        cbUnionPayCards.Checked = true;
                        txbUnionPayCards.Focus();
                        break;
                    case Keys.D2:
                        cbUnionPayCards.Checked = true;
                        txbUnionPayCards.Focus();
                        break;

                    case Keys.NumPad3:
                        cbCheck.Checked = true;
                        txbCheck.Focus();
                        break;
                    case Keys.D3:
                        cbCheck.Checked = true;
                        txbCheck.Focus();
                        break;

                    case Keys.NumPad4:
                        cbGuaZhang.Checked = true;
                        txtGuaZhang.Focus();
                        break;
                    case Keys.D4:
                        cbGuaZhang.Checked = true;
                        txtGuaZhang.Focus();
                        break;

                    case Keys.NumPad5:
                        cbOther.Checked = true;
                        cbxOther.Focus();
                        break;
                    case Keys.D5:
                        cbOther.Checked = true;
                        cbxOther.Focus();
                        break;
                    default:
                        break;
                }
            }
            #endregion

        }
View Code

 

posted on 2014-02-19 09:14  zxd543  阅读(295)  评论(0编辑  收藏  举报