如何在visual studio 2008中为按钮指定键盘快捷键 [英] How to assign keyboard shortcut to button in visual studio 2008

查看:73
本文介绍了如何在visual studio 2008中为按钮指定键盘快捷键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在visual studio 2008中为按钮指定键盘快捷键

how to assign keyboard shortcut to button in visual studio 2008

推荐答案

取决于你想要的快捷键类型:最简单的是旧式ALT +键组合,这真的很简单。



只需在Button.Text属性中的字母前添加一个'&'字符。例如,如果您希望在按ALT + O时按钮打开一个窗口,则将Text属性设置为& Open。要在ALT + N上执行此操作,请使用Ope& n。

当用户按住ALT键时,相应的字符将加下划线。



如果你想要别的东西,那么我们需要更多的细节。





你能做什么另一种选择,我需要一个字母才能执行按钮操作





如果您需要按钮的单个键,变得越来越难 - 菜单项很容易,但单个控件更难(因为它们没有输入,除非它们有焦点,这不是主意......)



首先,将Form.KeyPreview设置为 true

然后,覆盖ProcessCmdKey方法形式:

Depends on what type of shortcut you want: the simplest is the old style ALT+key combination, which is truly simple.

Just add an '&' character before the letter in the Button.Text property. For example if you want your button to open a window when you press ALT+O, then make the Text property "&Open". TO make it do it on ALT+N, use "Ope&n".
When the user holds the ALT key down, the appropriate characters will be underlined.

If you want something else, then we need more details.


"can u make an another option for it,that i need one letter to hit to perform the button action"


If you need a single key for buttons, that gets harder - it's easy for menu items, but individual controls are harder (because they don't get input unless they have the focus, which isn't quite the idea...)

First, set the Form.KeyPreview to true
Then, override the ProcessCmdKey method for the form:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
    if (keyData == (Keys.O))
        {
        myButtonToOpenSomething.PerformClick();
        return true;
        }
    return base.ProcessCmdKey(ref msg, keyData);
    }


这篇关于如何在visual studio 2008中为按钮指定键盘快捷键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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