【问题标题】:Windows form hot keys using ALT+Key, if the same key combination with case changeWindows 使用 ALT+Key 形成热键,如果相同的组合键改变大小写
【发布时间】:2017-07-28 10:13:52
【问题描述】:

我们创建了具有两个按钮取消和清除的窗体。 我们将按钮文本指定为 &Cancel 和 &clear 以作为 Alt+key 的快捷键组合。 但是当我们按下 Alt+c 时,它只适用于取消按钮。 相反,为什么它不会在 Windows 窗体中的这两个按钮之间进行选项卡,其工作方式类似于 VB6 表单中的选项卡。 如果按下 Alt+c,我需要在这两个按钮之间切换。 请建议需要设置任何表单属性或按钮属性来实现这一点?

【问题讨论】:

    标签: c# winforms visual-studio-2015


    【解决方案1】:

    您可以尝试覆盖 ProcessCmdKey 方法。如果您按 alt,松开 alt,然后按 c 键,则以下内容应该可以工作。

    private bool altPressed;
    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        if (altPressed)
            {
                if (keyData == Keys.C)
                {
                    this.SelectNextControl(ActiveControl, true, true, true, true);
                    altPressed = false;
                    return true;
                }
            }
            if (keyData == (Keys.Menu | Keys.Alt))
            {
                altPressed = true;
                return true;
            }
        return base.ProcessCmdKey(ref msg, keyData);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-10
      • 2013-04-06
      • 1970-01-01
      • 2018-02-23
      • 1970-01-01
      • 2011-02-21
      • 2017-12-10
      相关资源
      最近更新 更多