自定义菜单快捷键 [英] Customizing menu shortcut keys

查看:221
本文介绍了自定义菜单快捷键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作有它的顶部菜单中的应用程序。我想使用快捷键(即该片段),不同的方法:这是一个快捷键:<大骨节病> CTRL + <大骨节病> N ,<大骨节病> 1

I am working on an application that has a Menu on top of it. I want to use a different method for shortcut keys (being this snippet): this is for shortcut key: CTRL + N, 1

bool prefixSeen = false;

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
    if (prefixSeen)
    {
        switch (keyData)
        {
            case (Keys.Control | Keys.D1):
                MessageBox.Show("New file");
                prefixSeen = false;
                break;
        }
    }
    switch (keyData)
    {
        case (Keys.Control | Keys.n):
            prefixSeen = true;
        break;
    }

    return base.ProcessCmdKey(ref msg, keyData);
}



从代码的这里

下面是我的菜单

和我想的菜单项(右对齐)的快捷键(也应该仅仅被解释为一个字符串,我认为)。我怎样才能达到这样的效果?

And I want in menu items to be displayed (aligned on the right) the shortcut key (that should just be interpreted as a string I think). How can I achieve this effect?

谢谢,新年快乐给每个人。

Thanks in advance, and a Happy New Year to every one.

修改作为Visual Studio中内置的方法是:

the built-in method for Visual Studio is:

推荐答案

使用的 MenuItem.ShortCut MenuItem.ShowShortCut 属性。

Use the MenuItem.ShortCut and MenuItem.ShowShortCut Properties.

如果你想创建自己的自定义快捷键,这些属性将你无法工作,因为它们依赖于快捷键的预定枚举。在这种情况下,我会建议你将它添加到您的菜单的文本,有这样做的没有自动的方式。

If you want to create your own custom shortcuts these properties will not work for you, since they depend on a predetermined enumeration of ShortCut Keys. In that case I would suggest that you add it to the Text of your Menu, there is no automatic way of doing it.

由于有人指出,你正在使用 ToolStripMenuItems ,你应该能够independantly设置的 ShortCutKeyDisplayString 来>什么每次你的愿望。您仍然需要自己处理实际的快捷方式。

Since it was pointed out that you are using ToolStripMenuItems you should be able to independantly set the ShortCutKeyDisplayString to what every you wish. You will still need to handle the actual Shortcut yourself.

这篇关于自定义菜单快捷键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆