如何通过键盘快捷键来打开工具栏菜单? [英] How to open a toolbar menu by Keyboard short-cuts?
问题描述
我有我的窗体上的空白工具栏按钮,我在运行时将其所有的菜单和菜单项。
我需要一个键盘快捷方式添加到该工具栏的菜单。 ?我怎样才能做到这一点。
I have a blank toolbar button on my form and I am adding all its menus and menu items at run-time. I need to add a keyboard shortcut to the menus of this toolbar. How can I do this?
推荐答案
您可以使用与&在菜单项文本特殊符号来标记键。对这个简单的例子看看: HTTP://www.java2s .COM /代码/ CSHARP / Windows GUI的表格/ Addshortcutkeytoamenuitem.htm
You can use "&" special symbol in menu item text to mark key. Have a look on this simple example: http://www.java2s.com/Code/CSharp/GUI-Windows-Form/Addshortcutkeytoamenuitem.htm
编辑:
1)如果下拉按钮有一个文本将它足以设置'和,'符号,像菜单,使其下降。因此,在这种特殊情况下操作字符串分配给该按钮在代码中的一些点,已成为与&纠正措施。
1) If drop down button has a text in it it's enough to set '&' symbol, like for menus to make it drop. So in this specific case "Actions" string assigned to that button at some point in the code, have to become "&Actions".
2)如果只有图像下拉(没有文字上的按钮可见)不幸'和;'符号招不起作用。但你可以做,例如,这样的事情。 A 伪代码的:
2) If it's only image drop down (no text visible on the button) unfortunately '&' symbol trick doesn't work. But you can do, for example, something like this. A pseudocode:
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.Alt && e.KeyCode == Keys.A)
{
toolStripDropDownButton1.ShowDropDown();
}
base.OnKeyDown(e);
}
希望这有助于。
Hope this helps.
这篇关于如何通过键盘快捷键来打开工具栏菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!