C#程序添加快捷键

1.给按钮添加快捷键

按钮中Text属性后面添加关键字:(&O)—其中“O”表示快捷得键盘按钮。
即:Alt+O就可以键盘快捷键使用了
在这里插入图片描述

2.快捷键打开某个窗口或者事件

首先,给窗口注册键盘事件:keyDown
在这里插入图片描述
其次,代码中添加判断,判断某个按钮实现某个事件。代码示例如下:

/// <summary>
/// 键盘按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TFundBillAddDataForm_KeyDown(object sender, KeyEventArgs e)
{
    TextBox textBox = new TextBox();
    if (e.KeyCode == Keys.F7)
    {
        // 收款银行id
        if (string.IsNullOrEmpty(textBox7.Text) || SysContent.tBankInfo == null)
        {
            textBox = textBox7;
        }
        // 归属单位id
        else if (string.IsNullOrEmpty(textBox1.Text) || SysContent.tClientInfo == null)
        {
            textBox = textBox1;
        }
        // 资金类别id
        else if (string.IsNullOrEmpty(textBox5.Text) || SysContent.tFundTypeInfo == null)
        {
            textBox = textBox5;
        }
        // 资金状态id
        else if (string.IsNullOrEmpty(textBox6.Text) || SysContent.tFundStatusInfo == null)
        {
            textBox = textBox6;
        }

        // 防止重复刷新
        if (string.Equals(textboxName, textBox.Name) && panel1.Visible == true)
        {
            return;
        }
        switch (textBox.Name)
        {
            case "textBox1":
                List<TClientInfo> listTClientForm = tClientFormSQL.selectConditionData(textBox1.Text);
                // 资金归属单位赋值
                tClientRefrenceData(listTClientForm);
                break;
            case "textBox7":
                List<TBankInfo> listTBank = receivingBankFormSQL.selectConditionData(textBox7.Text);
                // 收款银行赋值
                tBankRefrenceData(listTBank);
                break;
            case "textBox5":
                List<TFundTypeInfo> listTFundType = fundTypeFormSQL.selectConditionData(textBox5.Text);
                // 资金类别列表赋值
                tFundTypeRefrenceData(listTFundType);
                break;
            case "textBox6":
                List<TFundStatusInfo> list = fundStatusFormSQL.selectConditionData(textBox6.Text);
                // 资金状态列表赋值
                tFundStatusRefrenceData(list);
                break;
            case "textBox8":
                List<TAccountInfo> listTAccountInfo = tAccountFormSQL.selectConditionData(textBox8.Text);
                // 预算科目列表赋值
                tAccountRefrenceData(listTAccountInfo);
                break;
            case "textBox9":
                List<TItemInfo> listTItemInfo = tItemFormSQL.selectConditionData(textBox9.Text);
                // 预算项目列表赋值
                tItemRefrenceData(listTItemInfo);
                break;
        }
        textboxName = textBox.Name;
        panel1.Visible = true;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

哎呦喂O_o嗨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值